PC Review


Reply
Thread Tools Rate Thread

Autofilter Row Count

 
 
James
Guest
Posts: n/a
 
      10th Dec 2008
Hi, I have the following code, how come I get the value of 1 everytime i do
rng.rows.count (which is wrong)? Im using rng.rows.count in another private
function. Thanks in advance

Public Sub RangeFind()
Dim shtName As String
Dim wShData As Worksheet
shtName = ActiveSheet.Name
Set wShData = ActiveWorkbook.Worksheets(shtName)

With wShData.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1,
..Columns.Count).SpecialCells xlCellTypeVisible)
On Error GoTo 0
End With
End Sub
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      10th Dec 2008
rng.rows.count will give you the number of rows in the first area of rng (and my
bet is your rng consists of multiple non-contiguous areas).

rng.rows.count is equivalent to rng.areas(1).rows.count

If you want to get the number of rows in the autofilter range (and set a
variable for just the details), you can do something like this that I saved from
a previous post:

With activesheet.AutoFilter.Range
If .Columns(1).Cells.SpecialCells(xlCellTypeVisible).Count = 1 Then
MsgBox "only the headers are visible"
else
'resize to avoid the header
'and come down one row
Set VisRng = .Resize(.Rows.Count - 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
End With

James wrote:
>
> Hi, I have the following code, how come I get the value of 1 everytime i do
> rng.rows.count (which is wrong)? Im using rng.rows.count in another private
> function. Thanks in advance
>
> Public Sub RangeFind()
> Dim shtName As String
> Dim wShData As Worksheet
> shtName = ActiveSheet.Name
> Set wShData = ActiveWorkbook.Worksheets(shtName)
>
> With wShData.AutoFilter.Range
> On Error Resume Next
> Set rng = .Offset(1, 0).Resize(.Rows.Count - 1,
> .Columns.Count).SpecialCells xlCellTypeVisible)
> On Error GoTo 0
> End With
> End Sub


--

Dave Peterson
 
Reply With Quote
 
James
Guest
Posts: n/a
 
      10th Dec 2008
Thanks for the reply. I ended up using:
rwcount = .Columns(1).Cells.SpecialCells(xlCellTypeVisible).Count -1
Worked great


"Dave Peterson" wrote:

> rng.rows.count will give you the number of rows in the first area of rng (and my
> bet is your rng consists of multiple non-contiguous areas).
>
> rng.rows.count is equivalent to rng.areas(1).rows.count
>
> If you want to get the number of rows in the autofilter range (and set a
> variable for just the details), you can do something like this that I saved from
> a previous post:
>
> With activesheet.AutoFilter.Range
> If .Columns(1).Cells.SpecialCells(xlCellTypeVisible).Count = 1 Then
> MsgBox "only the headers are visible"
> else
> 'resize to avoid the header
> 'and come down one row
> Set VisRng = .Resize(.Rows.Count - 1).Offset(1, 0) _
> .Cells.SpecialCells(xlCellTypeVisible)
> End With
>
> James wrote:
> >
> > Hi, I have the following code, how come I get the value of 1 everytime i do
> > rng.rows.count (which is wrong)? Im using rng.rows.count in another private
> > function. Thanks in advance
> >
> > Public Sub RangeFind()
> > Dim shtName As String
> > Dim wShData As Worksheet
> > shtName = ActiveSheet.Name
> > Set wShData = ActiveWorkbook.Worksheets(shtName)
> >
> > With wShData.AutoFilter.Range
> > On Error Resume Next
> > Set rng = .Offset(1, 0).Resize(.Rows.Count - 1,
> > .Columns.Count).SpecialCells xlCellTypeVisible)
> > On Error GoTo 0
> > End With
> > End Sub

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      11th Dec 2008
Take a look at this:
http://www.contextures.com/xlautofilter03.html

Regards,
Ryan---

--
RyGuy


"James" wrote:

> Thanks for the reply. I ended up using:
> rwcount = .Columns(1).Cells.SpecialCells(xlCellTypeVisible).Count -1
> Worked great
>
>
> "Dave Peterson" wrote:
>
> > rng.rows.count will give you the number of rows in the first area of rng (and my
> > bet is your rng consists of multiple non-contiguous areas).
> >
> > rng.rows.count is equivalent to rng.areas(1).rows.count
> >
> > If you want to get the number of rows in the autofilter range (and set a
> > variable for just the details), you can do something like this that I saved from
> > a previous post:
> >
> > With activesheet.AutoFilter.Range
> > If .Columns(1).Cells.SpecialCells(xlCellTypeVisible).Count = 1 Then
> > MsgBox "only the headers are visible"
> > else
> > 'resize to avoid the header
> > 'and come down one row
> > Set VisRng = .Resize(.Rows.Count - 1).Offset(1, 0) _
> > .Cells.SpecialCells(xlCellTypeVisible)
> > End With
> >
> > James wrote:
> > >
> > > Hi, I have the following code, how come I get the value of 1 everytime i do
> > > rng.rows.count (which is wrong)? Im using rng.rows.count in another private
> > > function. Thanks in advance
> > >
> > > Public Sub RangeFind()
> > > Dim shtName As String
> > > Dim wShData As Worksheet
> > > shtName = ActiveSheet.Name
> > > Set wShData = ActiveWorkbook.Worksheets(shtName)
> > >
> > > With wShData.AutoFilter.Range
> > > On Error Resume Next
> > > Set rng = .Offset(1, 0).Resize(.Rows.Count - 1,
> > > .Columns.Count).SpecialCells xlCellTypeVisible)
> > > On Error GoTo 0
> > > End With
> > > End Sub

> >
> > --
> >
> > Dave Peterson
> >

 
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
autofilter count glee Microsoft Excel Discussion 1 2nd Oct 2009 02:12 PM
Getting the count from autofilter Jason V Microsoft Excel Programming 2 16th Dec 2008 04:49 PM
autofilter row count Pierre Microsoft Excel Programming 3 21st Dec 2007 03:03 PM
AutoFilter and row count =?Utf-8?B?Qm9i?= Microsoft Excel Misc 5 29th Mar 2007 12:40 AM
Re: Count in Autofilter Phoenix Microsoft Excel Misc 2 31st Mar 2004 11:41 AM


Features
 

Advertising
 

Newsgroups
 


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