PDA

View Full Version : AutoFilter and Non Contiguous Ranges



philfer
11-16-2010, 08:31 AM
Hello,

I am using Autofilter for a date column which returns 13 row but of non contiguous ranges (i.e. rows 65-69, 283-285, 408).

I am trying to count and then loop through the rows.

I use :-

LastRow = FilterRange.Columns(1).SpecialCells(xlCellTypeVisible).Count

but it returns 4.

I try to loop through using :-

For i = 1 To LastRow

but after row 69 it moves to row 70 rather than 283.

Is there a way around this?

Thanks
Phil

GTO
11-16-2010, 08:55 AM
Try a For Each... By example, if the filter was in Col C:


Option Explicit

Sub exa()
Dim rng As Range
Dim Cell As Range

With Sheet1 '<---or ThisWorkbook.Worksheets("Sheet1")
Set rng = Range(.Range("C2"), .Cells(.Rows.Count, "C").End(xlUp))
For Each Cell In rng.SpecialCells(xlCellTypeVisible)
MsgBox Cell.Address
Next
End With

End Sub


Hope that helps,

Mark