通过Access VBA在Excel中添加格式条件 [英] Adding a format condition in Excel through Access VBA

查看:108
本文介绍了通过Access VBA在Excel中添加格式条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以目前我的代码中有这些行,

So currently i got these lines in my code,

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

我的目标是向其添加条件格式,因此,如果它等于= Required,范围为= $ C $ 2:$ C $ 3,则将背景变为红色,到目前为止,我在网上看到过一些代码,但似乎均不适用.我修改了一些现有代码以达到我的目的,因为我在xlExpression上看到错误未定义变量".谁能帮我吗?

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')"

推荐答案

您必须将xlExpression替换为2.

You have to replace xlExpression with 2.

这篇关于通过Access VBA在Excel中添加格式条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆