SOLVED VBA Search/Replace a FormatConditions not working

ACommandLineKindaGuy

Active Member
Joined
May 11, 2002
Messages
378
Office Version
  1. 365
Platform
  1. Windows
Now this is really wierd.

Cells B14:N23 on the "Directs" sheet have a single conditional formula that checks a condition with the particular cell as well as an absolute reference to cell M8.

eg, Cell B14 conditional format formula is =AND(B14<>"",$M$8="")

I want to strip the absolute reference to M8 in each cell to get =AND(B14<>"",M8=""), so here's what I wrote:

Code:
For Each c In Worksheets("Directs").Range("B14:N23")
    s1 = .FormatConditions(1).Formula1
    s1 = Replace(s1, "$M$8", "M8", 1)
    .FormatConditions(1).Modify xlExpression, , s1
Next

The problem is that now, cell C15 for example has a conditional format formula of =AND(C15<>"",N9="") when it should read =AND(C15<>"",M8="")

What the heck is going on? :oops:

SOLUTION: add the line
Code:
c.Activate
as the first line in the For Each routine

I just love how I never seem to get any responses to my posts. Gives me a nice warm fuzzy.
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,213,536
Messages
6,114,208
Members
448,554
Latest member
Gleisner2

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