Conditional Formatting in a Loop
This puts in the conditional format your code appears to want to put in. If
I am in A26, I am not sure why I would check A27 and A28, so I am not sure
that is the right formula, but you wrote it.
Sub BBB()
Set rng = Range(Range("A26"), Range("A26").End(xlDown))
With rng
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=$A26 = $A27"
.FormatConditions(1).Interior.ColorIndex = 35
.FormatConditions.Add Type:=xlExpression, Formula1:="$A27 = $A28"
.FormatConditions(2).Interior.ColorIndex = 35
'
' check to see if rate charged was incorrect - compare d & f
'
With .Offset(0, 3).Resize(, 3)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$D26<$F26"
.FormatConditions(1).Interior.ColorIndex = 39
End With
End With
End Sub
--
Regards,
Tom Ogilvy
"lost!!" wrote in message
...
Hi there,
I'm trying to use a loop to copy a conditional format from row to row.
The
conditional format is to compare row A### to the row above and the row
below
- if a duplicate is found then the colour should change.
The next part is to compare the value in D## to F## and if the result is
not
the same the colour should change. Here is the code I have used (it's
very
simple since I'm just new at programming):
' check to see if row is equal to row above or below
'
Range("A26").Select
While ActiveCell.Value < ""
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$A$26 =
$A$27"
Selection.FormatConditions(1).Interior.ColorIndex = 35
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="$A$27 =
$A$28"
Selection.FormatConditions(2).Interior.ColorIndex = 35
'
' check to see if rate charged was incorrect - compare d & f
'
ActiveCell.Offset(0, 3).Range("A1:C1").Select
Selection.FormatConditions.Delete
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=$D26<$F26"
Selection.FormatConditions(1).Interior.ColorIndex = 39
ActiveCell.Offset(1, -3).Range("A1").Select
Wend
I have tried removing the $ from the format but that didn't help either.
The format is copying but only looking at the data in row 26.
Please help!!!
|