Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default Autofilter Range

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




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Autofilter Range

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




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Autofilter Range

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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 421
Default Autofilter Range

Hi Nigel,

One way::

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim Rng2 As Range
Dim rCell As Range
Dim rFirst As Range
Dim rLast As Range
Dim i As Long

Set WB = Workbooks("myBook.xls") '<<==== CHANGE
Set SH = WB.Sheets("Sheet3") '<<==== CHANGE

With SH
If Not .AutoFilterMode Then
MsgBox Prompt:="No Autofilter found", _
Buttons:=vbCritical, _
Title:="No Autofilter"
Exit Sub
End If

Set Rng = .AutoFilter.Range.Columns(1)
With Rng
Set Rng = .Offset(1).Resize(.Rows.Count - 1)
End With

On Error Resume Next
Set Rng2 = Rng.SpecialCells(xlVisible)
On Error GoTo 0
End With

If Rng2 Is Nothing Then
MsgBox Prompt:=" There are no filtered rows"
Exit Sub
End If

For Each rCell In Rng2.Cells
i = i + 1
If rFirst Is Nothing Then
Set rFirst = rCell
End If
Set rLast = rCell
Next rCell

MsgBox Prompt:="The Auto filter contains " _
& i & " visible data rows" _
& vbNewLine _
& "The first visible cell is " _
& rFirst.Address(0, 0) _
& vbNewLine _
& "The last visible cell is " _
& rLast.Address(0, 0), _
Buttons:=vbInformation, _
Title:="Autofilter Report"
End Sub
'<<=============


---
Regards.
Norman


"Nigel" wrote in message
...
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







  #6   Report Post  
Posted to microsoft.public.excel.programming
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






  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default Autofilter Range

Thanks, nice idea I will try it out.

--

Regards,
Nigel




"Norman Jones" wrote in message
...
Hi Nigel,

One way::

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range
Dim Rng2 As Range
Dim rCell As Range
Dim rFirst As Range
Dim rLast As Range
Dim i As Long

Set WB = Workbooks("myBook.xls") '<<==== CHANGE
Set SH = WB.Sheets("Sheet3") '<<==== CHANGE

With SH
If Not .AutoFilterMode Then
MsgBox Prompt:="No Autofilter found", _
Buttons:=vbCritical, _
Title:="No Autofilter"
Exit Sub
End If

Set Rng = .AutoFilter.Range.Columns(1)
With Rng
Set Rng = .Offset(1).Resize(.Rows.Count - 1)
End With

On Error Resume Next
Set Rng2 = Rng.SpecialCells(xlVisible)
On Error GoTo 0
End With

If Rng2 Is Nothing Then
MsgBox Prompt:=" There are no filtered rows"
Exit Sub
End If

For Each rCell In Rng2.Cells
i = i + 1
If rFirst Is Nothing Then
Set rFirst = rCell
End If
Set rLast = rCell
Next rCell

MsgBox Prompt:="The Auto filter contains " _
& i & " visible data rows" _
& vbNewLine _
& "The first visible cell is " _
& rFirst.Address(0, 0) _
& vbNewLine _
& "The last visible cell is " _
& rLast.Address(0, 0), _
Buttons:=vbInformation, _
Title:="Autofilter Report"
End Sub
'<<=============


---
Regards.
Norman


"Nigel" wrote in message
...
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






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofilter a Date range Steen Excel Discussion (Misc queries) 0 November 25th 06 08:23 PM
Limiting the range of AutoFilter? CDiddy Excel Worksheet Functions 5 July 8th 06 08:20 PM
What is Range For Chart AutoFilter Range VBA? [email protected] Excel Discussion (Misc queries) 0 April 19th 06 05:30 PM
autofilter copy to new range Monique Excel Programming 3 July 19th 05 09:39 PM
Copy an autofilter range pauluk[_13_] Excel Programming 2 March 4th 04 04:28 PM


All times are GMT +1. The time now is 06:03 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"