【问题标题】:Conditional formatting is not working for dates comparison条件格式不适用于日期比较
【发布时间】:2020-10-05 00:45:02
【问题描述】:

尝试为两列实现条件格式(行着色) - 一个字符串和一个日期条件(我用两种方法执行此操作,但它们都不起作用):

> Dim y As Date
>     y = DateAdd("d", 30, Date) Debug.Print y Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
>      "=OR(AND($H2=""1. Qualify"",$P2=""Google"", Days(now(),$Z2)<30  ),AND($H2=""1. Qualify"",$P2=""AWS"", $Z2 <
> DateValue(y)))"
>          Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
>     With Selection.FormatConditions(1).Interior
>         .PatternColorIndex = xlAutomatic
>         .Color = vbRed
>         .TintAndShade = 0
>     End With
>     Selection.FormatConditions(1).StopIfTrue = False

知道原因吗?

【问题讨论】:

  • y 位于该公式的引号内,因此它不是变量,而只是文本“y”。
  • 谢谢,这是有用的信息。我将通过排除此选项继续深入研究它。第一个 - “Days(now(),$Z2)

标签: excel vba date formatting conditional-statements


【解决方案1】:

我的问题的解决方案是使用 NOW() 函数:

$Z2<NOW()+30

【讨论】:

    猜你喜欢
    • 2023-03-26
    • 1970-01-01
    • 2021-12-14
    • 1970-01-01
    • 1970-01-01
    • 2021-05-30
    • 2018-03-21
    • 1970-01-01
    • 2019-01-09
    相关资源
    最近更新 更多