Conditional Formatting rules for the whole worksheet in VBA

Viewed 17

In Excel itself, Conditional Formatting menu, one can select the rules within the whole worksheet. Yet, in VBA, FormatConditions is a property of a range, and not a property of the sheet object. How can get that list of FormatConditions which is displayed in the Excel as applying to the whole sheet?

1 Answers

The .cells property of a worksheet is a range that contains all cells of the sheet.

You can use a code like that to create a rule for the whole sheet:

With ActiveSheet.Cells.FormatConditions.Add(Type:=xlExpression, Formula1:="=VALUE(A1)>50")
    .Interior.Color = vbYellow
End With
Related