【发布时间】:2019-02-15 11:55:08
【问题描述】:
所以我想要一个代码来执行以下...
如果 K= Business 且 E= null 高亮E
和
如果 K= Business 且 F= null 高亮 F
每次我尝试它都会说类型不匹配或对象错误
Sub business()
Dim a As String
Dim b As String
Dim c As String
Set a.Value = Range("K2:K300")
Set b.Value = Range("E2:E300")
Set c.Value = Range("F2:F200")
If a = "Email" And b = "" Or c = "" Then
Cell.Interior.ColorIndex = 3
Else
Cell.Interior.ColorIndex = 0
End If
End Sub
【问题讨论】:
-
请edit 使用引发错误的代码提出问题。
-
这不需要 VBA - 您可以使用条件格式来做到这一点。
-
所以我想要一个到目前为止我得到的代码 Sub business() Dim a As String Dim b As String Dim c As String Set a.Value = Range("K2:K300") Set b .Value = Range("E2:E300") Set c.Value = Range("F2:F200") If a = "Email" And b = "" or c = "" Then Cell.Interior.ColorIndex = 3 Else Cell .Interior.ColorIndex = 0 End If End Sub
-
您将
a、b和c设置为数组,然后在If语句中测试它们,就好像它们是单独的值一样。只需在 E 列中放置一个条件格式,在 F 列中放置一个条件格式 - 例如=AND(K2="Email",E2="")和=AND(K2="Email",F2="") -
感谢您的回复。但我将此代码添加为大宏的一部分,这就是为什么我要寻找 vba 代码而不是条件格式。
标签: excel vba if-statement nested