#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 410
Default Case Statement

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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,718
Default Case Statement

Select Case Range("A1").Value
Case "Jim", "Bill": Drk = 1
Case "Jill", "Fred": Drk = 2
...
End Select



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

  #3   Report Post  
Posted to microsoft.public.excel.misc
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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Case Statement

I don't like GoTo's:

Option Explicit
Sub testme01()

Dim Drk As Long

Drk = 0
Do
Select Case Range("A1").Value
Case Is = "Jim", "Bill"
Drk = 1
Case Is = "Jill", "Fred"
Drk = 2
Case Else
Range("A1") = InputBox("this is not a valid name, " _
& "please enter a valid name and press enter.")
End Select
If Drk = 0 Then
'keep looking
Else
Exit Do
End If
Loop

MsgBox Drk

End Sub


And you don't give the user a way to cancel out of the loop???

And if case doesn't matter:

Select Case lcase(Range("A1").Value)
Case Is = lcase("Jim"), lcase("Bill")
Drk = 1
Case Is = lcase("Jill"), lcase("Fred")



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


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Case Statement Katie Excel Worksheet Functions 13 December 1st 08 07:32 PM
import external data sql case statement burkecrosby Excel Discussion (Misc queries) 0 January 25th 07 04:26 PM
IF STATMENT OR CASE STATEMENT Richard Excel Discussion (Misc queries) 2 January 10th 07 10:04 AM
Anyone actually get Case statement to work ... ? ForestFeeder Excel Worksheet Functions 3 April 21st 06 04:14 PM
CASE statement equivalent Beema Excel Worksheet Functions 1 December 15th 04 09:32 AM


All times are GMT +1. The time now is 04:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"