3 回答
TA贡献1818条经验 获得超11个赞
假设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
Next
End 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 cl
End Sub
TA贡献1852条经验 获得超7个赞
我建议使用OffsetHeaders位于第1行。请参见此示例
Option Explicit
Sub Sample()
Dim rRange As Range, filRange As Range, Rng as Range
'Remove any filters
ActiveSheet.AutoFilterMode = False
'~~> Set your range
Set rRange = Sheets("Sheet1").Range("A1:E10")
With rRange
'~~> Set your criteria and filter
.AutoFilter Field:=1, Criteria1:="=1"
'~~> Filter, offset(to exclude headers)
Set filRange = .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow
Debug.Print filRange.Address
For Each Rng In filRange
'~~> Your Code
Next
End With
'Remove any filters
ActiveSheet.AutoFilterMode = False
End Sub
TA贡献1811条经验 获得超6个赞
一种方法是向下过滤A1中的数据;
dim Rng as Range
set Rng = Range("A2", Range("A2").End(xlDown)).Cells.SpecialCells(xlCellTypeVisible)
...
for each cell in Rng
...
- 3 回答
- 0 关注
- 1094 浏览
相关问题推荐
添加回答
举报