VBA - using OR (or a logical equivalent)

Chris The Rock

Active Member
Joined
Feb 24, 2002
Messages
287
My brain is fried. Between VBA and SQL, sometimes I can't remember how to do certain things, like this:

I want to set a boolean variable = TRUE if any of the following conditions are met:
IF a cell's value contains "PCT" ,
OR
IF that cell's value contains "%",
OR
IF that cell's value contains "PERCENT"

I know how to use INSTR to find out if a string is found in another string, I just can't wrap my head around using 3 criteria. Sounds like the perfect time to use SELECT CASE, but I can't think of how it should go.

Here's how I'd code it if I only was looking for a single one of these criteria:
Code:
If InStr(1, UCase(rng_NewTarget.Value), "PCT") <> 0 Then
    bln_IsPCT = True
End If

Can I use "OR", like in SQL? Or is there a smarter way to do this?
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Chris The Rock

Active Member
Joined
Feb 24, 2002
Messages
287
I found a way to do this. Kinda clever. Anyone who digs this up in a search, just ask me and I'll tell you how I did it.
 

Forum statistics

Threads
1,181,102
Messages
5,928,065
Members
436,586
Latest member
latintxn

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
Top