SOLVED VBA Search/Replace a FormatConditions not working

ACommandLineKindaGuy

Active Member
Joined
May 11, 2002
Messages
331
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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,323
Messages
5,769,454
Members
425,549
Latest member
Bartekelese

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