Case is statement with And

neveu

Board Regular
Joined
Jan 27, 2009
Messages
225
hello,

i would need to create a Case is Statement where the criteria is complex, meaning i would have to use the AND.

how should it be written to work?

i would need something like

Select Case valuetocompare
case is <=3 AND case is >1

but if i write it like that i get an error.

any help is greatly appreciated
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Don't use Select Case - use If...Then...Else...End If
 
Upvote 0
So? There isn't a limit to If statements.
 
Upvote 0
Something like this should work:

Code:
Select Case valuetocompare
    Case 1 To 3
        'your code
    Case Else
        'your code
End Select
 
Upvote 0
True - if your complex criteria are simple ranges, then that will work. I confess I simply assumed they were more complicated than that! :)
 
Upvote 0
would be very hard for me to follow it and write it

Why would they be? The structure is virtually identical.

In my little world since IFs can do everything CASEs can do plus a lot more. CASE = pointless.
 
Upvote 0
Select Case can be much easier to read in a lot of circumstances. On the other hand, IF...End If is, allegedly, more efficient.
 
Upvote 0
You don't have to use AND in a Select Case Statement.
It works the same as a Nested If.
It's all in the order you write the case statements...

Rich (BB code):
Select Case SomeValue
    Case Is <=1
        'Do This
    Case Is <=3 
        'here you do not have to test for >1
        'because it's already handled in previous case <=1
        'Do That
    Case Is <=5
        'here you do not have to test for >3
        'because it's already handled in previous case <=3
        'Do Something Else
    Case Else
        'Do Nothing
End Select
 
Upvote 0

Forum statistics

Threads
1,216,095
Messages
6,128,790
Members
449,468
Latest member
AGreen17

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