VBA Conditional Formatting Issue/Bug

Scotster

Board Regular
Joined
May 29, 2017
Messages
59
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
I'm not sure if my code is wrong here or if I'm just missing something obvious.....

I'm using the following snippet to conditional format the range P4:P1000. If I manually type it all in it's absolutely fine. Using the following code it doesn't work. However, if I go into "Conditional Formatting", double click on the generated conditional format then simply hit "OK" it starts working. I've tried refreshing and everything else that I can think of. I have 10 programmatically generated conditional formats all working flawlessly, it's just this one that's the issue. It seems it might be down to using the "Match" functionality?

Set cond = Range("P4:P1000").FormatConditions.Add(xlExpression, , "=MATCH(""*CRIT*"",UPPER($W4:$X4),0)")
cond.Interior.Color = vbRed
cond.Font.Color = vbWhite
cond.Font.Bold = RgBold

if you can think of anything it would be greatly appreciated :)
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Changed it to.....

Code:
Set cond = Range("P4:P1000").FormatConditions.Add(xlExpression, , "=MATCH(""*CRIT*"",$W4:$X4,0)")


Seems to work fine now. Surprised that it's not case sensitive and that the "UPPER" functionality stops it from working.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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