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 關注
- 1157 瀏覽
相關問題推薦
添加回答
舉報