Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50167

Cell references error with recorded Conditional Formatting (Formula) macro

$
0
0
I need to apply Conditional Formatting using a formula =$D3<>$D2. As I record the macro (see below), the Conditional Formatting works fine. But when I run the macro, and look at the Conditional Formatting rule, is shows different row references =$D5<>$D4 in the formula and formatting doesn't get applied correctly.

What's going on?

(Note that cell A3 is the top left cell in the current region)
Code:

'Clear old Conditional Formatting
    Cells.FormatConditions.Delete
   
'Conditional Format rows with a top border if the Invoice # (col D) is different than cell above
    With Range("A3").CurrentRegion
        .FormatConditions.Add Type:=xlExpression, Formula1:="=$D3<>$D2"
        .FormatConditions(.FormatConditions.Count).SetFirstPriority
        .FormatConditions(1).Borders(xlTop).LineStyle = xlContinuous
        .FormatConditions(1).StopIfTrue = False
    End With


Viewing all articles
Browse latest Browse all 50167

Trending Articles