过滤范围内的操作

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

可能我知道是否有更直接的选择?

specialcells(xlcelltypevisible).Areas(4)
并不总是有效,因为第四滤波器范围可能每次都不同。
    

端是循环穿过区域

Option Explicit Sub VBAArray2() Const NUM = 4 Dim rng As Range, lastrow As Long Dim i As Long, m As Long, n As Long ' set filter With Sheets(1) lastrow = .Cells(.Rows.Count, "A").Rows(xlUp).Row .Range("A1").AutoFilter 3, "A<B" Set rng = .Range("A2:A" & lastrow).SpecialCells(xlCellTypeVisible) End With ' check enough rows If rng.Cells.Count < NUM Then MsgBox "Row count < " & NUM, vbCritical Exit Sub End If ' iterate areas Do m = n i = i + 1 n = n + rng.Areas(i).Rows.Count Loop While n < NUM ' result MsgBox rng.Areas(i).Cells(NUM - m) End Sub
excel vba
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.