I have the following code and am banging my head against the wall why it does not work.
When using the commented line with the range as $K10 it works fine when I assign a named range rngValidation it does not work. The defined name range of “ptrValidationCells” is set to $K10.
Sub FormatConditions_2()
Dim rngToFormat As Range
Dim rngValidation As Range
Set rngToFormat = ActiveSheet.Range("inpInputCells")
Set rngValidation = ActiveSheet.Range("ptrValidationCell")
' rngToFormat.FormatConditions.Add Type:=xlExpression, Formula1:="=$K10<>FALSE"
rngToFormat.FormatConditions.Add Type:=xlExpression, Formula1:="=rngValidation <>FALSE"
With rngToFormat.FormatConditions(2).Interior
.PatternColorIndex = xlAutomatic
.Color = RGB(255, 192, 0)
.TintAndShade = 0
End With
With rngToFormat.FormatConditions(2).Font
.Bold = True
.Italic = False
.Color = RGB(192, 0, 0)
.TintAndShade = 0
End With
End Sub
Thanks for any assistance
FormatConditions executes in the Workbook environment, not the VBA environment (if I can put it this way), so you need to use a named range and not a VBA variable.
Alternatively,
should do the trick.