Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inputbox Cancel not Behaving

Status
Not open for further replies.

BatFace

Technical User
Oct 17, 2001
24
AU
I have the following code to find whatever is entered into the input box - move 11 columns right and enter "Y" in this cell;

Dim strFindText As String

strFindText = InputBox("type a number")
If strFindText <> &quot;&quot; Then Range(&quot;p1&quot;).Value = strFindText

With Sheets(&quot;sheet1&quot;).Range(&quot;d:d&quot;)
Set c = .find(strFindText, LookIn:=xlValues)
c.Offset(0, 11).Select
ActiveCell.FormulaR1C1 = &quot;Y&quot;

msg = &quot;Another Number?&quot;
ans = MsgBox(msg, vbYesNo)

Do Until ans = vbNo
strFindText = InputBox(&quot;type a number&quot;)
Set c = .find(strFindText, LookIn:=xlValues)

c.Offset(0, 11).Select
ActiveCell.FormulaR1C1 = &quot;Y&quot;

msg = &quot;Another Number?&quot;
ans = MsgBox(msg, vbYesNo)

Loop

End With

When cancel is pressed on the input box, a &quot;Y&quot; is put in cell o5 (only and always o5)...I thought the second line of code would stop it but it hasn't....I must need to add something else - but I'm only a newbie to vba and am not sure what?

Thanks in advance for your help.
[bat]

ps I have posted this in the vba forum also [wink]
 
Hi BatFace
Code:
    Do Until ans = vbNo
    strFindText = InputBox(&quot;type a number&quot;)
    If strFindText = &quot;&quot; Then Exit Sub
<--- Add this line here
Code:
Set c = .Find(strFindText, LookIn:=xlValues)

    c.Offset(0, 11).Select
    ActiveCell.FormulaR1C1 = &quot;Y&quot;

    msg = &quot;Another Number?&quot;
    ans = MsgBox(msg, vbYesNo)

    Loop

rgrds
LSTAN
 
YAAAAAYYYY This works! Thanks so much LSTAN, I knew it would end up being something simple [blush]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top