Select Case - With multiple variables?

Stildawn

Board Regular
Joined
Aug 26, 2012
Messages
200
Hi All

I have a bunch of data and I need a why to test if a set of conditions are met, and then do more code if different sets are.

For example, 3 variables which are in A1, B1 & C1.

I was wondering if there was a way to get a select case type code to work but each case is testing each value in the A1, B1, C1 above.

Completely made up code below which explains what I am after:

Code:
Select Case
  Case Is A1 = 1 and B1 = 2 and C1 = 3
    Do something here
  Case Is A1 = 2 and B1 = 1 and C1 = 4
    Do something else here
  Case Is A1 = 5 and B1 = 6 and C1 = 1
    Do something different here
End Select

I know how to do standard select cases and how to use ranges etc the above is just a made up example to get my point across.

Or is there another way to do the above? Basically test multiple variables combined to execute different sets of code, without of course doing massive If statements or select cases within select cases etc.

Any help would be greatly appreciated.

Thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Heres a possible:

Code:
Select Case Range("A1") & "|" & Range("B1") & "|" & Range("C1")
    Case "1|2|3"
        MsgBox "yes"
    'etc
End Select

Just be aware of its limitations if pipes may be part of the cell contents. Very unlikely to get wrong result but potential.
 
Upvote 0
If A1, B1 and C1 are variables (similar could be done if they are cell references but the syntax would change a little) then you can use a Select Case structure like this

Code:
Select Case True
  Case A1 = 1 And B1 = 2 And C1 = 3
    Do something here
  Case A1 = 2 And B1 = 1 And C1 = 4
    Do something else here
  Case A1 = 5 And B1 = 6 And C1 = 1
    Do something different here
End Select
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,215
Members
452,618
Latest member
Tam84

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top