Inputbox with VBA

J

Jeff

Hello,

I have this procedure:
iMatch = Application.Match(908, Range("A:A"), 0)
I need help to include an Inputbox that would prompt the user to enter "908".
The inputbox msg should read " Customer number"
 
B

Bob Phillips

Dim ans
Dim fValid As Boolean

fValid = False
Do
ans = InputBox("Input Customer Number")
If ans = "" Then
Exit Sub
Else
If IsNumeric(ans) Then
If ans > 0 Then
fValid = True
iMatch = Application.Match(ans, Range("A:A"), 0)
'more code
End If
End If
End If
Loop Until fValid

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 
D

Dave Peterson

dim CustNumber as long
dim iMatch as variant
custNumber = application.inputbox(prompt:="Customer Number",type:=1)
if custnumber = 0 then
exit sub
end if

imatch = Application.Match(custnumber, Range("A:A"), 0)
if iserror(imatch) then
'not found
else
'found
end if

application.inputbox with type:=1 forces the user to enter numbers.
 
D

Dave Peterson

I think this:
iMatch = Application.Match(ans, Range("A:A"), 0)
needs to be:
iMatch = Application.Match(clng(ans), Range("A:A"), 0)
if that table is really numbers.
 
Top