Class FormatCondition (Excel VBA)
The class FormatCondition represents a conditional format.
The main procedures of class FormatCondition are Delete, FormatConditions.Add, FormatConditions.AddAboveAverage, FormatConditions.AddColorScale, FormatConditions.AddDatabar, FormatConditions.AddIconSetCondition, FormatConditions.AddTop10, FormatConditions.AddUniqueValues and FormatConditions.Delete
To use a FormatCondition class variable it first needs to be instantiated, for example
Dim rng As Range: Set rng = Dim fcd As FormatCondition Set fcd = rng.FormatConditions.Add(Type:=xlAboveAverageCondition, Formula1:="", String:="")
Here is an example of processing the FormatCondition items in a collection.
Dim rng As Range: Set rng = Dim fcdFormatCondition As FormatCondition For Each fcdFormatCondition In rng.FormatConditions Next fcdFormatCondition
Some procedures in this class have been grouped together in themes and are described on separate theme pages
Formula with its procedures Formula1 and Formula2
Add with its procedures FormatConditions.Add, FormatConditions.AddAboveAverage, FormatConditions.AddDatabar, FormatConditions.AddIconSetCondition and FormatConditions.AddTop10
These are the main methods of the FormatCondition class
Delete - Deletes the object.
FormatConditions.AddColorScale - Returns a new ColorScale colorscale representing a conditional formatting rule that uses gradations in cell colors to indicate relative differences in the values of cells included in a selected range.
FormatConditions.AddUniqueValues - Returns a new UniqueValues uniquevalues representing a conditional formatting rule for the specified range.
FormatConditions.Delete - Deletes the object.
Modify - Modifies an existing conditional format.
Worksheets(1).Range("e1:e10").FormatConditions(1) _ .Modify xlCellValue, xlLess, "=$a$1"
AppliesTo returns a Range object specifying the cell range to which the formatting rule is applied.
Borders returns a Borders collection that represents the borders of a style or a range of cells (including a range defined as part of a conditional format).
Sub SetRangeBorder() With Worksheets("Sheet1").Range("B2").Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 3 End With End Sub
DateOperator specifies the Date operator used in the format condition.
Font returns a Font object that represents the font of the specified object.
Interior returns an Interior object that represents the interior of the specified object.
NumberFormat returns or sets the number format applied to a cell if the conditional formatting rule evaluates to True.
Operator returns a Long value that represents the operator for the conditional format.
With Worksheets(1).Range("e1:e10").FormatConditions(1) If .Operator = xlLess And .Formula1 = "5" Then .Modify xlCellValue, xlBetween, "5", "15" End If End With
Parent returns the parent object for the specified object. Read-only.
Priority returns or sets the priority value of the conditional formatting rule. The priority determines the order of evaluation when multiple conditional formatting rules exist on a worksheet.
PTCondition returns a Boolean value indicating if the conditional format is being applied to a PivotTable.
ScopeType returns or sets one of the constants of the XlPivotConditionScope enumeration, which determines the scope of the conditional format when it is applied to a PivotTable.
StopIfTrue returns or sets a Boolean value that determines if additional formatting rules on the cell should be evaluated if the current rule evaluates to True.
Text returns or sets a String value specifying the text string used by the conditional formatting rule.
TextOperator returns or sets one of the constants of the XlContainsOperator enumeration, specifying the text search performed by the conditional formatting rule.
Type returns a Long value, containing an XlFormatConditionType value, that represents the object type.
FormatConditions.Count returns a Long value that represents the number of objects in the collection.
FormatConditions.Parent returns the parent object for the specified object. Read-only.