View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\) Rick Rothstein \(MVP - VB\) is offline
external usenet poster
 
Posts: 2,202
Default Input Box data validation

If there were a mathematical "pattern" of some sort, then perhaps the Like
operator or a mathematical equation could be used to test the validity of
the entered number. However, I don't see such a pattern, so I probably would
test the validity of the user's entry like this...

Dim BLI As String
Dim ValidNumbers As String
ValidNumbers = "*1406*1408*1410*1411*1415*1430*1440*" & _
"1450*1460*1465*1470*1475*1485*1490*" & _
"1492*1495*1499*1501*1502*"
..........
..........
..........
Do
BLI = InputBox("Which BLI would you like to enter?")
Loop Until InStr(ValidNumbers, "*" & BLI & "*") Or BLI = ""
..........
..........

I broke up the ValidNumbers assignment in convenient places to stop you
newsreader from possibly breaking it up haphazardly. You can recombine the
three continued lines into a single line statement if you so wish (just make
sure there is an asterisk between every numbers). Note that the user must
enter either one of your numbers **OR** an empty string (assuming you want
to leave the user with an escape mechanism; perhaps they have the wrong
number and need to get out the validity checking loop). Because the empty
string is a possibility, you will probably need to add code to handle that
situation.

Rick


"Mathew" wrote in message
...
Rick: Here are the numbers: 1406, 1408, 1410, 1411, 1415, 1430, 1440,
1450,
1460, 1465, 1470, 1475, 1485, 1490, 1492, 1495, 1499, 1501, 1502. I've
eliminate 3 others from the list by dealing with them elsewhere in the
macro.
I'm curious as to why these could have a bearing on how to approach the
code. By the way, thanks for the help!

"Rick Rothstein (MVP - VB)" wrote:

Can you show us the 22 allowable numbers? (It may have a bearing on how
to
approach the code.)

Rick


"Mathew" wrote in message
...
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.