首页 > 解决方案 > 在特定日期后停止保存的电子表格上的条件格式

问题描述

我正在处理一个电子表格,我想在其中格式化下周即将到来的日期。代码工作正常,但下周过去后,格式继续,我不希望那样。我只希望从生成文件之日起的下一周进行格式化。为了澄清,我举个例子:

我想在任何时间点打开此保存的电子表格,并且仅格式化 10 月 6 日至 10 月 12 日这一周。这是我使用的代码,在生成电子表格的那一天之后,我可以输入一个命令来停止格式化吗?

    Macro1 Macro
    With Application
    .ScreenUpdating = False
    .Calculation = xlCalculationManual
    End With
    Cells.Select
    Range("B1").Activate
    Selection.FormatConditions.Add Type:=xlTimePeriod, DateOperator:=7
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Font
        .Bold = True
        .Italic = False
        .Color = -16711681
        .TintAndShade = 0
    End With
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 5287936
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Range("D2").Select
    ActiveWindow.SmallScroll Down:=-30
End Sub

标签: excelvba

解决方案


推荐阅读