Thread: Case Statement
View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
JLatham JLatham is offline
external usenet poster
 
Posts: 3,365
Default Case Statement

You could do something like this. I've written it as a Sub that needs to be
called somehow.

Note that in VBA, "Bill" < "BILL" nor does "Bill" = "bill", so you may need
to add some conversion to all uppercase or such to make sure that entries are
acceptabile or not.

Sub TestCase()
Dim testResult As Boolean
Dim Drk As Integer

Do While testResult = False
Select Case Worksheets("Sheet1").Range("A1")
Case Is = "John", "Jim", "Jack", "Bill"
Drk = 1
testResult = True
Case Is = "Ralph", "Mary", "Tobias"
Drk = 2
testResult = True
Case Else
Worksheets("Sheet1").Range("A1") = InputBox("Enter Valid Name", "Bad
Name", "Quit")
If Worksheets("Sheet1").Range("A1") = "Quit" Then
Exit Sub
End If
End Select
Loop
MsgBox "Drk = " & Drk
End Sub


"jlclyde" wrote:

Is there anyway to set up this code to use OR for a case statement or
a way to check multiple things without putting in another case is =?
the code below is a general idea of what I am trying to do.

Thanks,
Jay

E:
Select Case Range("A1") .value
Case is = "Jim" or "Bill"
Drk = 1
Case is = "Jill" or "Fred"
Drk = 2
case else
range("A`1")=Inputbox("this is not a valid name, please enter a valid
name and press enter.")
goto E
End Select