【问题标题】:Conditional Formatting Error VBA条件格式错误 VBA
【发布时间】:2017-03-28 12:06:05
【问题描述】:

我想知道是否有人可以帮忙?!我在以下行收到错误:

.Add Type:=xlExpression, Formula1:= _
    "=IF($E1<>"",AND($E1<TODAY(),$F1=""Awaiting Information"")) = 1"

这是下面的代码。

Sub ConditionalFormat()

Sheets("NACO").Cells.FormatConditions.Delete

 With Worksheets("NACO").Columns("A:N").FormatConditions
**.Add Type:=xlExpression, Formula1:= _
    "=IF($E1<>"",AND($E1<TODAY(),$F1=""Awaiting Information"")) = 1"**
With .Item(.Count).Interior
    .Color = 255
End With

.Add Type:=xlExpression, Formula1:= _
    "=IF($E1<>"",AND($E1<TODAY(),$F1=""On Going"")) = 2"
With .Item(.Count).Interior
    .Color = 225
End With

.Add Type:=xlExpression, Formula1:= _
    "=IF($E1<>"",AND($E1<TODAY(),$F1=""Awaiting Quotation"")) = 3"
With .Item(.Count).Interior
    .Color = 255
End With

.Add Type:=xlExpression, Formula1:= _
    "=$F1=""On Going"" = 4"
With .Item(.Count).Interior
    .Color = RGB(247, 150, 70)
End With
End With
End Sub

有人能解释一下为什么会发生错误吗?跟“”有关系吗?

【问题讨论】:

  • $E1&lt;&gt;"" 等于$E1&lt;&gt;" 需要加倍
  • 当您尝试在文字字符串中包含文字双引号字符时,您需要双引号。所以 $E` "" 需要是 $E1 """"
  • 感觉有点像木板。它的“”,正如我所想的那样。令人沮丧。我遇到的问题是它添加了条件格式但没有将它们应用于范围。我做错了什么?

标签: excel vba formatting conditional


【解决方案1】:

你能不能试着把公式改成这个:

=IF(AND($E1&lt;&gt;"",$E1&lt;TODAY(),$F1="Awaiting Information")=1?

【讨论】:

  • 啊,如果我使用 AND / OR,我不需要 IF 语句?
  • @ShawnCartwright,其实我不知道你的条件是什么。但您可能是对的,请参阅编辑后的版本。
猜你喜欢
  • 2015-02-28
  • 2011-10-02
  • 1970-01-01
  • 2017-03-05
  • 1970-01-01
  • 1970-01-01
  • 2018-05-28
  • 2016-10-02
  • 1970-01-01
相关资源
最近更新 更多