PC Review


Reply
Thread Tools Rate Thread

Autofilter Range

 
 
Nigel
Guest
Posts: n/a
 
      6th May 2008
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
(E-Mail Removed)



 
Reply With Quote
 
 
 
 
ND Pard
Guest
Posts: n/a
 
      6th May 2008
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
> (E-Mail Removed)
>
>
>

 
Reply With Quote
 
Nigel
Guest
Posts: n/a
 
      6th May 2008
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
(E-Mail Removed)



"ND Pard" <(E-Mail Removed)> wrote in message
news:0F426339-1D60-44D1-A135-(E-Mail Removed)...
> 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
>> (E-Mail Removed)
>>
>>
>>


 
Reply With Quote
 
ND Pard
Guest
Posts: n/a
 
      6th May 2008
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
> (E-Mail Removed)
>
>
>
> "ND Pard" <(E-Mail Removed)> wrote in message
> news:0F426339-1D60-44D1-A135-(E-Mail Removed)...
> > 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
> >> (E-Mail Removed)
> >>
> >>
> >>

>

 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      6th May 2008
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" <nigel-(E-Mail Removed)> wrote in message
news:14131CC9-3587-45D7-8408-(E-Mail Removed)...
> 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
> (E-Mail Removed)
>
>
>


 
Reply With Quote
 
Nigel
Guest
Posts: n/a
 
      7th May 2008
Neat trick using a helper column, I will give it ago. Thanks

--

Regards,
Nigel
(E-Mail Removed)



"ND Pard" <(E-Mail Removed)> wrote in message
news:078E4F9F-3B65-4E82-843E-(E-Mail Removed)...
> 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
>> (E-Mail Removed)
>>
>>
>>
>> "ND Pard" <(E-Mail Removed)> wrote in message
>> news:0F426339-1D60-44D1-A135-(E-Mail Removed)...
>> > 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
>> >> (E-Mail Removed)
>> >>
>> >>
>> >>

>>


 
Reply With Quote
 
Nigel
Guest
Posts: n/a
 
      7th May 2008
Thanks, nice idea I will try it out.

--

Regards,
Nigel
(E-Mail Removed)



"Norman Jones" <(E-Mail Removed)> wrote in message
news:8A2C7FDD-E71A-4AF1-8B81-(E-Mail Removed)...
> 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" <nigel-(E-Mail Removed)> wrote in message
> news:14131CC9-3587-45D7-8408-(E-Mail Removed)...
>> 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
>> (E-Mail Removed)
>>
>>
>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Limiting the range of AutoFilter? CDiddy Microsoft Excel Worksheet Functions 5 8th Jul 2006 08:20 PM
Numbering a Range Using Autofilter =?Utf-8?B?dGFueWE=?= Microsoft Excel Misc 3 19th Jun 2006 03:40 PM
What is Range For Chart AutoFilter Range VBA? Dennis@NoSpam.com Microsoft Excel Misc 0 19th Apr 2006 05:30 PM
selecting date range / data range autofilter hansiman Microsoft Excel Discussion 1 24th Feb 2005 12:21 AM
Autofilter with Range problem kaon Microsoft Excel Programming 1 24th Aug 2004 11:37 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:19 AM.