Excel列条件格式

时间:2015-12-03 22:24:00

标签: excel excel-vba excel-formula worksheet-function conditional-formatting vba

我有一张Excel表格,我需要应用一些条件格式,并对如何操作感到困惑。

我需要做的是使一列值(在我的情况下为G列)为红色,如果另一列(E列)中的日期超过五天,并且如果另一列中没有值(第I列)

我还需要它,以便第一个值(在G列中)如果有一个值添加到第二个条件列(第一列),则会恢复为常规黑色。

另一个问题是,即使在保存或运行下面的代码之前符合要求的条件格式,之后CF也不会保留:

这是我们的“显示最新”或折叠代码:

    Sub Collapse1()
'
' Collapse Macro
' Collapses rows to show only the most recent issuance of each unique Document Number
'

'
    Range("Table1[[#Headers],[Document Number]]").Select
    Cells.FormatConditions.Delete
    Selection.AutoFilter
    Selection.AutoFilter
    ActiveSheet.ListObjects("Table1").Sort. _
        SortFields.Clear
    ActiveSheet.ListObjects("Table1").Sort. _
        SortFields.Add Key:=Range("Table1[Document Number]"), SortOn:= _
        xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    ActiveSheet.ListObjects("Table1").Sort. _
        SortFields.Add Key:=Range("Table1[Issuance" & Chr(10) & "Date]"), SortOn:=xlSortOnValues _
        , Order:=xlDescending, DataOption:=xlSortNormal
    With ActiveSheet.ListObjects("Table1"). _
        Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("Table1[Document Number]").Select
    Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
        "=COUNTIF($A$12:A12,A12)>1"
    Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
    With Selection.FormatConditions(1).Interior
        .PatternColorIndex = xlAutomatic
        .Color = 255
        .TintAndShade = 0
    End With
    Selection.FormatConditions(1).StopIfTrue = False
    Range("Table1[[#Headers],[Document Number]]").Select
    ActiveSheet.ListObjects("Table1").Range.AutoFilter Field:=1, Criteria1:=RGB _
        (255, 255, 255), Operator:=xlFilterNoFill
End Sub

1 个答案:

答案 0 :(得分:0)

不同的解释。请选择G栏和HOME>样式 - 条件格式,新规则...,使用公式确定要格式化的单元格格式化此公式的值:

=AND(E1<>"",E1<TODAY()-5,I1="")

格式化... ,选择您选择的格式(不是黑色),确定,确定。

这会在五天后触发。

相关问题