条件格式优先

时间:2019-11-20 16:59:58

标签: excel vba formatting conditional-statements

我无法为VBA条件格式设置优先级列表。在下面的代码中,如果我的优先级顺序为3-2-1,这似乎可以按预期工作,但是我希望顺序相反。如果将其设置为1-2-3,不仅顺序不会在工作表中更改,而且无法将颜色/字体应用于1和2位置。

我使用我的代码设置优先级不正确。

Sub SetConds()

Dim Tracker As Worksheet
Set Tracker = Sheets("Tracker")


    Tracker.Range("D:D").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=AND(D1>TODAY(),D1<=(TODAY()+7))"
    Selection.FormatConditions(Selection.FormatConditions.Count).Priority = 1
    With Selection.FormatConditions(1).Font
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 128
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False

    Tracker.Range("D:D").Select
    Selection.FormatConditions(1).StopIfTrue = False
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=AND(D1>TODAY(),D1<=(TODAY()+14))"
    Selection.FormatConditions(Selection.FormatConditions.Count).Priority = 2
    With Selection.FormatConditions(1).Font
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 26367
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False

    Tracker.Range("D:D").Select
    Selection.FormatConditions(1).StopIfTrue = False
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=AND(D1>TODAY(),D1<=(TODAY()+365))"
    Selection.FormatConditions(Selection.FormatConditions.Count).Priority = 3
    With Selection.FormatConditions(1).Font
        .ThemeColor = xlThemeColorDark1
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 26112
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False


    Tracker.Range("A1").Select
End Sub

0 个答案:

没有答案
相关问题