Select Case

J

John Howard

Is possible to use multiple AND statements in a single Select Case scenario?

e.g. Something like: Select Case Range("A1") .Value AND Range("B1").Value
Case x and y
Do sometning
End Select

I know that the above syntax does not work, but if multiples are possible,
what is the syntax for both the Select Case line and subsequent Case lines?
 
D

Doug Robbins - Word MVP on news.microsoft.com

You should be able to do something like

Dim A1B1
A1B1 = Range("A1").Value & Range("B1").Value
' or if the values are numeric, it would be better to use
A1B1 = Range("A1").Value + Range("B1").Value
'but of course 2 + 3 is the same as 3 + 2 so that might not work for you.
Select Case A1B1
Case

Other wise

Select Case Range("A1").Value
Case somethingA1
Select Case Range("B1").Value
Case somethingB1
someaction
Case somethingelseB1
some other action
'etc
End Select
Case somethingelseA1
Select Case Range("B1").Value
Case somethingB1
someaction
Case somethingelseB1
some other action
'etc
End Select
'etc
End Select


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
J

John Howard

Hi Doug,

It looks like the nested Select Case will be the way for me to go as I need
to later compare the two values selected.
Many thanks for taking the time to point me in the right direction.
--
Regards
John Howard
Sydney, Australia


Doug Robbins - Word MVP on news.microsof said:
You should be able to do something like

Dim A1B1
A1B1 = Range("A1").Value & Range("B1").Value
' or if the values are numeric, it would be better to use
A1B1 = Range("A1").Value + Range("B1").Value
'but of course 2 + 3 is the same as 3 + 2 so that might not work for you.
Select Case A1B1
Case

Other wise

Select Case Range("A1").Value
Case somethingA1
Select Case Range("B1").Value
Case somethingB1
someaction
Case somethingelseB1
some other action
'etc
End Select
Case somethingelseA1
Select Case Range("B1").Value
Case somethingB1
someaction
Case somethingelseB1
some other action
'etc
End Select
'etc
End Select


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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