Add Method (FormatConditions Collection)
Applies To
FormatConditions collection object.
Description
Adds a new conditional format. Returns a FormatCondition object that represents the new conditional format.
Syntax
expression.Add(Type, Operator, Formula1, Formula2)
expression Required. An expression that returns a FormatConditions object.
Type Required Long. Specifies whether the conditional format is based on a cell value or an expression. Can be either of the following XlFormatConditionType constants: xlCellValue or xlExpression.
Operator Optional Variant. The conditional format operator. Can be one of the following XlFormatConditionOperator constants: xlBetween, xlEqual, xlGreater, xlGreaterEqual, xlLess, xlLessEqual, xlNotBetween, or xlNotEqual. If Type is xlExpression, the Operator argument is ignored.
Formula1 Optional Variant. The value or expression associated with the conditional format. Can be a constant value, a string value, a cell reference, or a formula.
Formula2 Optional Variant. The value or expression associated with the second part of the conditional format when Operator is xlBetween or xlNotBetween (otherwise, this argument is ignored). Can be a constant value, a string value, a cell reference, or a formula.
Remarks
You cannot define more than three conditional formats for a range. Use the Modify method to modify an existing conditional format, or use the Delete method to delete an existing format before adding a new one.
See Also
Formula1 property, Formula2 property, Modify method (FormatCondition object), Operator property.
Example
This example adds a conditional format to cells E1:E10.
With Worksheets(1).Range("e1:e10").FormatConditions _
.Add(xlCellValue, xlGreater, "=$a$1")
With .Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = 6
End With
With .Font
.Bold = True
.ColorIndex = 3
End With
End With