View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Nigel[_2_] Nigel[_2_] is offline
external usenet poster
 
Posts: 735
Default Autofilter Range

Neat trick using a helper column, I will give it ago. Thanks

--

Regards,
Nigel




"ND Pard" wrote in message
...
Well, there's always more than one way to skin a cat.

You could try this, add a new column (say to the far right) of your data.
In each cell except the header row enter something, say: =row()

Do NOT put a header on this column.

Filter your data including the last column and then try this macro:

Sub FilteredData_1st_n_Last_Rows()
Selection.CurrentRegion.Select
Selection.SpecialCells(xlCellTypeLastCell).Select
MsgBox "Last Row = " & ActiveCell.Row
MsgBox "First Row = " & ActiveCell.End(xlUp).Row
End Sub

This should work; at least it did when I tried it.

Good Luck.

"Nigel" wrote:

Thanks for the reply, I was rather hoping to avoid selecting cells and to
scan the filtered list looking for hidden=false rows. My list could be
very
large (100k rows) and this approach would be very slow.

Thanks again

--

Regards,
Nigel




"ND Pard" wrote in message
...
Open your VBA editor (Alt & F11), insert a Module, copy and paste the
macro
below.

Go Back to your spreadsheet and place your cursor in any of the
Filtered
cells.

Run the macro (Alt & F8).

Good Luck.

Sub FilteredData_1st_n_Last_Rows()
Selection.CurrentRegion.Select
Range(ActiveCell.Offset(1), ActiveCell.Offset _
(Selection.Rows.Count - 1, Selection.Columns.Count - 1)).Select
Do While ActiveCell.Height = 0
ActiveCell.Offset(1).Select
Loop
MsgBox "First Row = " & ActiveCell.Row
Selection.CurrentRegion.Select
MsgBox "Last Row = " &
Selection.SpecialCells(xlCellTypeLastCell).Row
End Sub

"Nigel" wrote:

Hi All
After I apply an autofilter, how can I determine the first visible row
number and last visible row number of the filtered list ?

Cheers

--

Regards,
Nigel