View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
mathew mathew is offline
external usenet poster
 
Posts: 75
Default Input Box data validation

JNW: Thanks alot! I'll give it a try!

"JNW" wrote:

Try this. (You'll need to have your valid list of allowable numbers on a
sheet somewhere or modify the code to have it look at an array)


Sub getinfo()
Dim res As Variant
ActiveCell.Value = InputBox("Which BLI would you like to enter?")
res = Application.Match(ActiveCell.Value, Range("b1:b5"), 0)
'change above range to match the location of your
'valid list of allowable numbers
If Len(ActiveCell.Value) < 4 Then
GoTo NotCorrect
End If
If IsError(res) Then
GoTo NotCorrect
End If
Exit Sub

NotCorrect:
MsgBox "try again"
getinfo 'may need to change this based on how the inputbox is called
End Sub

One problem that could occur is you could run out of stack space if the user
enters in a wrong value too many times. One way you could correct this is
make the msgbox that says try again be more meaningful by including valid
entries.
i.e.
msgbox "you must use one of the following codes:" & _
vbcrlf & vbcrlf & "1111" & vbcrlf & "2222"

etc.

--
JNW


"Mathew" wrote:

I have a very complicated spreadsheet that many different users are filling
out. It is a complex spreadsheet that I cannot change. I've got a macro to
help them input data into this spreadsheet. I need a little help with it.

How would you create an input box that checks to see if the data entered is
correct? Below is the code:
ActiveCell.Value = InputBox("Which BLI would you like to
enter?")

What is needed is to check the BLI number entered, which must be a 4 digit
number, i.e. to verify if it is long enough, and if it is one of the 22
allowable numbers. Normally, I'd use a data validation for the cell in the
spreadsheet but the users are "getting lost" in the spreadsheet. Any help
would be appreciated.