There has to be a better way... If/or statements

rjperket

New Member
Joined
Aug 16, 2010
Messages
20
Hi all,

I am having trouble with one part of a piece of code where I want to say if the value in a certain cell is equal to one of multiple values and I think there must be a better way to do it. Right now I have a ridiculous number of or statements and it looks something like this:

Code:
            If ECpresent.Offset(1, -14).Value = "B01" _
            Or ECpresent.Offset(1, -14).Value = "B02" _
            Or ECpresent.Offset(1, -14).Value = "B03" _
            Or ECpresent.Offset(1, -14).Value = "B04" _
            Or ECpresent.Offset(1, -14).Value = "B05" _
            Or ECpresent.Offset(1, -14).Value = "B06" _
            Or ECpresent.Offset(1, -14).Value = "B07" _
            Or ECpresent.Offset(1, -14).Value = "B08" _
            Or ECpresent.Offset(1, -14).Value = "B09" _
            Or ECpresent.Offset(1, -14).Value = "B10" Then

Anyone have any suggestions?

Can I use a wildcard in some way like "B*"?


Thanks in advance!

Ryan
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Another way of saying the same thing:

Code:
For Each c In Range("B1:B10")
If c.Value = ECpresent.Offset(1, -14).Value Then
'Do something or don't do something
Exit For
End If
Next
Code:
 
Upvote 0
How is this the same thing?
The B01 B02 B03 etc in the original post are just text strings, not cell references.

Another way of saying the same thing:

Code:
For Each c In Range("B1:B10")
If c.Value = ECpresent.Offset(1, -14).Value Then
'Do something or don't do something
Exit For
End If
Next
Code:
 
Upvote 0
How is this the same thing?
The B01 B02 B03 etc in the original post are just text strings, not cell references.


That is a real Senior Moment, Jonmo1. Don't know what I was thinking.
 
Upvote 0
Thanks everyone for your speedy replies!

I used this method just because I was most familiar with it:
Code:
If Left(ECpresent.Offset(1, -14), 1) = "B" Then

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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