在宏/ VBA中使用3个条件的条件格式 [英] Conditional formatting using 3 conditions in Macro/VBA

查看:645
本文介绍了在宏/ VBA中使用3个条件的条件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Excel中编写一个宏,如果满足以下条件,则会将整行显示为绿色:

I would like to program a macro in Excel that would highlight the entire row green if the following conditions are met:

Emergency Type (Column B) = """"
In Window (Column N) = "On time"
Status (Column O) = "Successful"

范围是动态的,但为了这个例子的目的,它是 A2:P236 。 br>
我希望有任何帮助。谢谢。

The range is dynamic, but for the purpose of this example it is A2:P236.
I would appreciate any help on this. Thanks.

推荐答案

以编程方式尝试这样:

Sub ApplyConditionalFormatting()

Dim applyto As Range

Set applyto = Range("A2:P236") 'you can make this dynamic

Range("A2").FormatConditions.Add Type:=xlExpression, Formula1:= _
    "=AND($B2="""",$N2=""On Time"",$O2=""Successful"")"
With Range("A2").FormatConditions(1)
    .SetFirstPriority
    With .Interior
        .PatternColorIndex = xlAutomatic
        .Color = 5287936
        .TintAndShade = 0
    End With
    .ModifyAppliesToRange applyto
    .StopIfTrue = False
End With

End Sub

HTH。

这篇关于在宏/ VBA中使用3个条件的条件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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