How do I include a wider range in my code??

N

nrage21

I have the following input box running when a workbook is open...

Sub ZipCode()
MyInput = InputBox("Please enter Zip Code")
If MyInput = "10023" Then Worksheets("Sheets").Select
If MyInput = "10024" Then .... and so on for the whole NYC metro area
End Sub

Now want to create a message box for the zip codes that are not
included for example 00000,99999,66666. How do I accomplish this in few
lines of code???

I started with the following... but this is obviously illegal.... I
don't know how to include a wider range of values....

Sub ZipCode()
If MyInput = "22222 to 99999" Then MsgBox "Area NOT covered",
vbOKOnly, "TRY AGAIN!"
End Sub

Can any1 help??
 
N

nrage21

Thx Beto.

I found another way by experimenting....

Sub ZipCode()
MyInput = InputBox("Please enter Zip Code")
If MyInput = "10023" Then Worksheets("Sheet2").Select
If MyInput = (22222) < (99999) Then MsgBox "Area NOT covered",
vbOKOnly, "TRY AGAIN!"
End Sub

Any # between 22222 and 99999 will trigger the msgbox. :)
 
B

Beto

nrage21 said:
Sub ZipCode()
If MyInput = "22222 to 99999" Then MsgBox "Area NOT covered",
vbOKOnly, "TRY AGAIN!"
End Sub

Replace MyInput = "22222 to 99999" with:

Val(Myinput) >= 22222 And Val(MyInput) <= 99999

Regards,
 
B

Beto

nrage21 said:
I found another way by experimenting....

Sub ZipCode()
MyInput = InputBox("Please enter Zip Code")
If MyInput = "10023" Then Worksheets("Sheet2").Select
If MyInput = (22222) < (99999) Then MsgBox "Area NOT covered",
vbOKOnly, "TRY AGAIN!"
End Sub

Any # between 22222 and 99999 will trigger the msgbox. :)

Are you sure?
I tried your code and the message box pop-ups everytime, with any
argument. The condition is always true...

Regards,
 

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