如何过滤非红细胞?

问题描述 投票:0回答:1

以下代码可以成功过滤Red Cells

Sub Macro1()
Sheets("Sheet1").Range("A1:E500").AutoFilter Field:=1, Criteria1:=RGB(255, 0, 0), Operator:=xlFilterCellColor
End Sub

我正在寻找可以过滤不是红细胞的vba代码。

excel vba filter colors
1个回答
0
投票
Sub FilterNotRedCells()
    Dim ws As Worksheet
    Set ws = Sheets("Sheet1")
    
    ' Clear any existing filters
    If ws.AutoFilterMode Then ws.AutoFilterMode = False
    
    ' Apply filter to show all cells that are not red
    ws.Range("A1:E500").AutoFilter Field:=1, _
        Criteria1:=RGB(255, 0, 0), _
        Operator:=xlFilterCellColor, _
        VisibleDropDown:=False
    
    ' Reapply the filter, excluding red cells (showing non-red)
    ws.Range("A1:E500").AutoFilter Field:=1, _
        Criteria1:=RGB(255, 0, 0), _
        Operator:=xlFilterNoFill
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.