我知道如何在一个条件下做到这一点,事实上我已经在我的宏中使用它了:
Dim cl, dl As Range, LR As Long, ws As Worksheet
Set ws = ActiveSheet
LR = ws.Range("A" & Rows.Count).End(xlUp).Row
For Each cl In ws.Range("AK2:AK" & LR).SpecialCells(xlCellTypeVisible)
If cl.Value < 10 Then cl.EntireRow.Hidden = True
Next cl
接下来,我需要隐藏更多行,但这次基于两个标准。 如果 AL 列包含值 PASS,那么我需要查看 H 列并隐藏其中值不同于 1 的所有行。这可能吗?我尝试定义第二个范围称为 dl,但它不起作用。下面是我两次失败的尝试。任何帮助将不胜感激。
LR = ws.Range("A" & Rows.Count).End(xlUp).Row
For Each cl In ws.Range("AL2:AL" & LR).SpecialCells(xlCellTypeVisible)
If cl.Value = "PASS" Then Set dl = ws.Range("H2:H" & LR).SpecialCells(xlCellTypeVisible)
If dl.Value <> 1 Then dl.EntireRow.Hidden = True
End If
Next cl
LR = ws.Range("A" & Rows.Count).End(xlUp).Row
For Each cl In ws.Range("H2:H" & LR).SpecialCells(xlCellTypeVisible)
Set dl = ws.Range("AL2:AL" & LR).SpecialCells(xlCellTypeVisible)
If dl.Value = "PASS" And cl.Value = 1 Then cl.EntireRow.Hidden = True
Next cl
使用
cl.Row
引用与 cl
同一行的 H 列中的单元格。
For Each cl In ws.Range("AK2:AK" & LR).SpecialCells(xlCellTypeVisible)
If cl.Value = "PASS" And ws.Cells(cl.Row, "H").Value <> 1 Then
cl.EntireRow.Hidden = True
End If
Next cl