How to apply conditional formatting for only visible cells?

后端 未结 2 378
别跟我提以往
别跟我提以往 2021-01-29 02:30

I am using Excel-2010, I have applied 3scale conditional formatting for Excel range A1:F100, on a Dropdown macro hide/unhide will be actioned, and hide/unhide is not sequential,

2条回答
  •  离开以前
    2021-01-29 03:10

    As commented, it should be something like this:

    Sub ject()
        Dim rng As Range
        With Sheet1 '~~> change to your actual sheet
            .Range("A1:F100").FormatConditions.Delete
            Set rng = .Range("A1:F100").SpecialCells(xlCellTypeVisible)
            .Range("A1").FormatConditions.AddColorScale 3
            With .Range("A1").FormatConditions(1)
                With .ColorScaleCriteria(1)
                    .Type = xlConditionValueLowestValue
                    .FormatColor.Color = RGB(255, 0, 0)
                End With
                With .ColorScaleCriteria(2)
                    .Type = xlConditionValuePercentile
                    .FormatColor.Color = RGB(255, 255, 0)
                End With
                With .ColorScaleCriteria(3)
                    .Type = xlConditionValueHighestValue
                    .FormatColor.Color = RGB(0, 255, 0)
                End With
                .ModifyAppliesToRange rng
            End With
        End With
    End Sub
    

    Everytime this routine is run or called, it re-applies formatting to visible ranges.
    It can be incorporated to an existing code or run separately. HTH.

提交回复
热议问题