Monday, October 15, 2012

How to add Format Conditions using Excel VBA

Sub Format_Condition_Example()

Dim oFc As FormatCondition
Dim oRange As Range

Set oRange = Range("B2:B5")
Set oFc = oRange.FormatConditions.Add(xlCellValue, xlLess, "0.5")
oFc.Interior.ColorIndex = 3
Set oFc = oRange.FormatConditions.Add(xlCellValue, xlBetween, "0.5", "0.80")
oFc.Interior.ColorIndex = 6
Set oFc = oRange.FormatConditions.Add(xlCellValue, xlGreater, "0.80")
oFc.Interior.ColorIndex = 4

End Sub

No comments: