Adding a format condition in Excel through Access

2019-07-24 13:16发布

So currently i got these lines in my code,

.Range("C2").Formula = "=IF(B2 = """"," & """REQUIRED""" & "," & """""" & ") "
.Range("C3").Formula = "=IF(B3 = """"," & """REQUIRED""" & "," & """""" & ") "

my goal was to add a conditional formatting to it, so if it equal to Required from the range =$C$2:$C$3 turn background red so far ive seen some codes online but none of them seem to apply. I modified some existing code for my purposes by i get an error on xlExpression "variable not defined". Can anyone help me?

.Range("C2:C3").Selection.FormatConditions.Delete 
.Range("C2:C3").Selection.FormatConditions.Add TYPE:=xlExpression, Formula1:="=(=$C$2:$C$23 = 'REQUIRED')"

1条回答
冷血范
2楼-- · 2019-07-24 13:23

You have to replace xlExpression with 2.

查看更多
登录 后发表回答