根据已过滤范围内的单元格值隐藏行

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

我有一个包含大约 13k 行的 Excel 文件。

我隐藏了一些列,然后根据其他一些列进行过滤。在此之后我还剩下 100-150 行。到目前为止我的宏有效。

下一步是过滤掉具有值的行< 10 in column AH.

我可以以此作为第一步,但当循环 100-150 行就足够时,循环 13k 行似乎很乏味。

我尝试了两个版本。

  1. 陷入了一个很长的循环,可能是因为它循环了 13k 行而不是 100-150 行?
Dim LR As Long
Dim iCell As Range
LR = Range("A" & Rows.Count).End(xlUp).Row
Set iCell = Range("A2:BS" & LR).Cells.SpecialCells(xlCellTypeVisible)
For Each iCell In Range("AH:AH").Cells
    If iCell.Value < 10 Then Rows(iCell.Row).EntireRow.Hidden = True
Next iCell
  1. 隐藏初始过滤后留下的所有行
Dim cl As Range, rng As Range, LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
Set rng = Range("A2:BS" & LR)
For Each cl In rng.SpecialCells(xlCellTypeVisible)
    If cl.Value < 10 Then Rows(cl.Row).EntireRow.Hidden = True
Next cl

如何仅循环已过滤的剩余 100-150 行范围?

excel vba range filtering
1个回答
0
投票

也许试试这个:

    Dim cl As Range, LR As Long, ws As Worksheet
    
    Set ws = ActiveSheet ' or whatever
    LR = ws.Range("A" & Rows.Count).End(xlUp).Row
    
    For Each cl In ws.Range("AH2:AH" & LR).SpecialCells(xlCellTypeVisible)
        If cl.Value < 10 Then cl.EntireRow.Hidden = True
    Next cl
© www.soinside.com 2019 - 2024. All rights reserved.