VBA自动过滤器 - 如果满足多个条件,则禁用单元

时间:2017-08-10 08:35:55

标签: excel vba excel-vba

此自动过滤器过滤单元格,因此字段6到8包含"是":

With Range("F6:H500")
    .AutoFilter Field:=6, Criteria1:="yes"
    .AutoFilter Field:=7, Criteria1:="yes"
    .AutoFilter Field:=8, Criteria1:="yes"
End With

我怎样才能达到相反的目的?我想拥有所有组合,但不是每个单元格包含"是"。所以"是","是",空白..或"是",空白,空白

感谢。

更新
试过这个,但失败了:

For Each r In rng.Rows
    If rng.Cells(r.Row, 1).Text Like "yes" Then
        r.EntireRow.Hidden = True
    End If
Next r

1 个答案:

答案 0 :(得分:1)

您可以使用以下内容进行过滤:

Sub HideRows()
Dim ws As Worksheet
Set ws = Worksheets(1)

With ws
    For i = 6 To 500
        If .Cells(i, 6) Like "yes" And .Cells(i, 7) Like "yes" And .Cells(i, 8) Like "yes" Then
            .Rows(i).EntireRow.Hidden = True
        End If
    Next
End With
End Sub

取消隐藏:

Sub ShowAllRows()
    Rows.EntireRow.Hidden = False
End Sub