【问题标题】:Multiple Conditional Formatting Variables in VBAVBA 中的多个条件格式变量
【发布时间】:2017-08-14 17:53:19
【问题描述】:

这是我目前所拥有的:

'Highlight If N=19 & R=OR
Range("G4:R1000").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:="=$N4=19"
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
    .PatternColorIndex = xlAutomatic
    .Color = 255
    .TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = True

我正在尝试根据多个标准突出显示几个单元格。如果 N=19 并且如果 R=OR。我只能让 N=19 部分工作。

【问题讨论】:

  • 改成Formula1:="=AND($N4=19, $R4=""OR"")"
  • 完美运行,并且能够根据我的需要进一步修改它。谢谢!

标签: vba excel excel-formula conditional-formatting


【解决方案1】:

我相信我在上面的 cmets 中所做的公式调整应该可以解决您的问题,但这是我清理记录的条件格式代码的方法。

With Worksheets("Sheet1")
    With .Range("G4:R1000")
        With .FormatConditions.Add(Type:=xlExpression, Formula1:="=AND($N4=19, $R4=""OR"")")
            With .Interior
                .PatternColorIndex = xlAutomatic
                .Color = 255
                .TintAndShade = 0
            End With
            .SetFirstPriority
        End With
        .FormatConditions(1).StopIfTrue = True
    End With
End With

删除冗长的限定代码(例如Selection.FormatConditions(Selection.FormatConditions.Count)...)使其更具可读性。

【讨论】:

    猜你喜欢
    • 2017-03-05
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 2016-10-02
    • 2017-11-13
    • 2021-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多