简体   繁体   English

VBA自动筛选-如果满足多个条件,请禁用单元格

[英]VBA Autofilter - disable cells if multiple conditions are met

This autofilter filters cells so field 6 through 8 contain "yes": 此自动过滤器过滤单元格,因此字段6到8包含“是”:

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

How can I achieve the opposite? 我该如何实现相反的目标? I would like to have every combination, but NOT if every cell contains "yes". 我想拥有所有组合,但如果每个单元格都包含“是”,则不会。 So "yes", "yes", blank.. or "yes", blank, blank 所以“是”,“是”,空白..或“是”,空白,空白

thanks. 谢谢。

update 更新
tried this, but failed: 尝试了这个,但是失败了:

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

You can filter with: 您可以使用以下过滤器:

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

And unhide with: 并隐藏:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM