Reputation: 73
I'm trying to write some vba code that adds conditional formatting to a sheet, however I keep running into an application defined error. The following is my code
With sheet1.Range("C2:C")
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=NOT(ISBLANK($B2))"
.FormatConditions(1).Interior.ColorIndex = RGB(225, 242, 255)
End With
Any suggestions on why this could be happening?
Thanks!
Upvotes: 0
Views: 47
Reputation: 3801
Range("C2:C")
is not a valid range, make it fixed, or the following makes it dynamic:
Then change your ColorIndex
to just Color
:
With Range("C2:C" & Cells(Rows.Count, "C").End(xlUp).Row)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:="=NOT(ISBLANK($B2))"
.FormatConditions(1).Interior.Color = RGB(225, 242, 255)
End With
Upvotes: 1