inputbox help

K

kckar

i have an inputbox on one of my worksheets. on another worksheet i hav
a listof about 40 numbers. i want to be able to cancel the inputbox an
it exits on when i hit the cancel button. when i enter an incorrec
number i want to the box to have another box pop up that says incorrec
id.
my code so far is

Sub boxes()
'sub for user input boxes
Range("f8").Offset(Range("checkoutindex"), 0) = Range("checkoutindex")
Range("g8").Offset(Range("checkoutindex"), 0) = InputBox("Enter Produc
ID #")
Range("a2") = Range("g8").Offset(Range("checkoutindex"))
Range("i8").Offset(Range("checkoutindex"), 0) = InputBox("Ente
Quantity")
End Sub


Private Sub CommandButton1_Click()
'add item button
Range("checkoutindex") = Range("checkoutindex") + 1
boxes
Do While Range("a4") = True
MsgBox ("Incorrect ID #")
boxes
Loop
End Sub



thank yo
 
P

protonLeah

Try something like this:
Do
gotnumber = InputBox("Enter your number")
'
'If input is cancelled, exit the macro
'
If gotnumber = "" Then
Exit Sub
End If
'
' If "gotnumber" is holding a value then verify it is valid (in th
list)
'
With Worksheets("numberlist").Range("A:A")
Set verifynum = .Find(gotnumber, LookIn:=xlValues)
End With
'
'If the number is not in the list give the user an error message an
loop
'back for another try
'
If verifynum Is Nothing Then 'i.e., no
found in list
retval = MsgBox(gotnumber &" is not a valid number "
vbInformation)

'
iStrikeCount = iStrikeCount + 1
'
If iStrikeCount = 3 Then 'After three trys, close an
exit macro
Exit Sub
End If
Else: Exit Do
End If
Loop
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top