假设A2:A11我的自动过滤器位于,则单元格中的数字为1到10 A1。我现在过滤以仅显示大于5的数字(即6、7、8、9、10)。此代码将只显示可见的单元格:Sub SpecialLoop() Dim cl As Range, rng As Range Set rng = Range("A2:A11") For Each cl In rng If cl.EntireRow.Hidden = False Then //Use Hidden property to check if filtered or not Debug.Print cl End If NextEnd Sub也许有更好的方法,SpecialCells但是以上方法在Excel 2003中对我有用。编辑刚刚找到了更好的方法SpecialCells:Sub SpecialLoop() Dim cl As Range, rng As Range Set rng = Range("A2:A11") For Each cl In rng.SpecialCells(xlCellTypeVisible) Debug.Print cl Next clEnd Sub
一种方法是向下过滤A1中的数据;dim Rng as Rangeset Rng = Range("A2", Range("A2").End(xlDown)).Cells.SpecialCells(xlCellTypeVisible)...for each cell in Rng ...