I have a worksheet that has several regions with conditional formatting, maybe ten rules in all. I noticed lately that it was running very slowly. I checked the conditional formatting rules ("Manage Rules") and found that there were literally dozens, maybe
hundreds of rules in the list. Since deleting them one-by-one is extremely tedious, I decide to create a macro by recording the deletion of the first rule in the list. The recorded macro really surprised me:
Cells.FormatConditions.Delete ' This is the one rule that I deleted???
Range("F4:F23").Select ' Excel recorded the re-creation of all the rules!!!
Range("B4").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=IF($E5<> $F4,IF($E5="""",0,1),0)=1"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.ColorIndex = 3
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
Range("E5:E23").Select
Range("B4").Activate
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=IF($E4<> $F3,IF($E4="""",0,1),0)=1"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.ColorIndex = 3
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
Range("B4:D23").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=IF(LEFT($B4,1)=""-"",1,0)=1"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.ColorIndex = 5
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True
etc, etc, etc (hundreds of lines of code were created).
Two questions:
1. Why are my conditional formatting rules duplicating themselves so many times?
2. How can I delete them without clearing out all my other formatting as well?
Thanks,
Eric
Excel 2007 SP2
Windows XP SP3