I would like the right code for using conditional formatting. I have data for sum of 4 Quarter sales form ("K8:K207"). I want to apply conditional formatting where I have 3 conditions:
Please help me how I can write a code using loop.
You don't need a loop for this. You can just add a new FormatCondition to your range object.
lLow = 90000
lHigh = 100000
Set rng = Range("K8:K207")
rng.FormatConditions.Delete ' delete any pre-existing formatting
' add greater than condition
With rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlGreater, Formula1:="=" & lHigh)
.Interior.Color = rgbLimeGreen
End With
' add middle condition
With rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlBetween, Formula1:="=" & lLow, Formula2:="=" & lHigh)
.Interior.Color = rgbGold
End With
' add less than condition
With rng.FormatConditions.Add(Type:=xlCellValue, Operator:=xlLess, Formula1:="=" & lLow)
.Interior.Color = rgbRed
End With
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With