Dirkasaurus
New Member
- Joined
- Aug 15, 2011
- Messages
- 6
I read Bill's "VBA and Macros in Excel 2007" chapter on Conditional Formatting. That said, I'm finding that iterating through the ConditionalFormats.Formula1 collection to not work as expected.
For example, a cell shows in the User Interface the following three rules:
Rule 1: "=AND(LENB(B17)>0,UPPER($F$9)="STATIC")"
Rule 2: "=LENB($B17)=0"
Rule 3: "=UPPER($F$9)="DYNAMIC""
When I use this code, I get the following result:
Dim oCF as ConditionalFormat
Dim rng as Range
Set rng = Range("J17").selection
For Each oCF in rng.ConditionalFormats
debug.print oCF.Formula1
Next
The output in the Immediate Window is:
=LENB($B17)=0
=LENB($B17)=0
=LENB($B17)=0
============================================
To address this a different way, I then try this in the Immediate Window (with the active cell J17):
?Activecell.FormatConditions.count
3
?
?Activecell.FormatConditions(1).Formula1
=LENB($B17)=0
?Activecell.FormatConditions(2).Formula1
=LENB($B17)=0
?Activecell.FormatConditions(3).Formula1
=LENB($B17)=0
============================================
It does not make any difference the order of the rules in J17. Nor does it make any difference if I enter the rule via the UI or if I use VBA Code to place the rules in the cell using R1C1 notation (as recommended in Bill's book).
Does anyone have any comments about the short coming of iterating through the FormatConditions.Formula1 collection and correctly obtaining the formula that are associated with the rules?
Thanks!
For example, a cell shows in the User Interface the following three rules:
Rule 1: "=AND(LENB(B17)>0,UPPER($F$9)="STATIC")"
Rule 2: "=LENB($B17)=0"
Rule 3: "=UPPER($F$9)="DYNAMIC""
When I use this code, I get the following result:
Dim oCF as ConditionalFormat
Dim rng as Range
Set rng = Range("J17").selection
For Each oCF in rng.ConditionalFormats
debug.print oCF.Formula1
Next
The output in the Immediate Window is:
=LENB($B17)=0
=LENB($B17)=0
=LENB($B17)=0
============================================
To address this a different way, I then try this in the Immediate Window (with the active cell J17):
?Activecell.FormatConditions.count
3
?
?Activecell.FormatConditions(1).Formula1
=LENB($B17)=0
?Activecell.FormatConditions(2).Formula1
=LENB($B17)=0
?Activecell.FormatConditions(3).Formula1
=LENB($B17)=0
============================================
It does not make any difference the order of the rules in J17. Nor does it make any difference if I enter the rule via the UI or if I use VBA Code to place the rules in the cell using R1C1 notation (as recommended in Bill's book).
Does anyone have any comments about the short coming of iterating through the FormatConditions.Formula1 collection and correctly obtaining the formula that are associated with the rules?
Thanks!