Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Row count a filtered sheet

I have written a code that will filters a sheet however I now need to
count the rows that come out of the filter. Is there any way to do
this?

Thanks,

Peter

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Row count a filtered sheet


Sub CountVisibleRows()
Dim rng As Range, rng1 As Range
Set rng = ActiveSheet.AutoFilter.Range.Columns(1).Cells
Set rng1 = rng.SpecialCells(xlVisible)
MsgBox rng1.Count - 1 & " rows are visible"
End Sub




another way is using the Subtotal command. If a specific column will have
values in every row

Sub countvisibleRows2()
Dim rng As Range, cnt As Long
Set rng = ActiveSheet.AutoFilter.Range.Columns(1).Cells
cnt = Application.Subtotal(3, rng)
MsgBox cnt - 1 & " rows are visible"
End Sub

--
Regards,
Tom Ogilvy

"Peter" wrote:

I have written a code that will filters a sheet however I now need to
count the rows that come out of the filter. Is there any way to do
this?

Thanks,

Peter


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Row count a filtered sheet

rng.SpecialCells(xlCellTypeVisible).Rows.Count

where rng is the range that you have filtered.

--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Peter" wrote in message
ps.com...
I have written a code that will filters a sheet however I now need to
count the rows that come out of the filter. Is there any way to do
this?

Thanks,

Peter



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Row count a filtered sheet

On 5 Feb, 14:39, Tom Ogilvy
wrote:
Sub CountVisibleRows()
Dim rng As Range, rng1 As Range
Set rng = ActiveSheet.AutoFilter.Range.Columns(1).Cells
Set rng1 = rng.SpecialCells(xlVisible)
MsgBox rng1.Count - 1 & " rows are visible"
End Sub

another way is using the Subtotal command. If a specific column will have
values in every row

Sub countvisibleRows2()
Dim rng As Range, cnt As Long
Set rng = ActiveSheet.AutoFilter.Range.Columns(1).Cells
cnt = Application.Subtotal(3, rng)
MsgBox cnt - 1 & " rows are visible"
End Sub

--
Regards,
Tom Ogilvy



"Peter" wrote:
I have written a code that will filters a sheet however I now need to
count the rows that come out of the filter. Is there any way to do
this?


Thanks,


Peter- Hide quoted text -


- Show quoted text -


Tom that was brilliant!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Row count a filtered sheet

Hi Tom

I was looking through discussion groups to find the same thing, and came
across this, so I didn't have to post a question. Thanks very much, people
like you make such a difference to VBA hopelesses like me, your'e a star.
I've rated the post as helpful.

Aehan

"Tom Ogilvy" wrote:


Sub CountVisibleRows()
Dim rng As Range, rng1 As Range
Set rng = ActiveSheet.AutoFilter.Range.Columns(1).Cells
Set rng1 = rng.SpecialCells(xlVisible)
MsgBox rng1.Count - 1 & " rows are visible"
End Sub




another way is using the Subtotal command. If a specific column will have
values in every row

Sub countvisibleRows2()
Dim rng As Range, cnt As Long
Set rng = ActiveSheet.AutoFilter.Range.Columns(1).Cells
cnt = Application.Subtotal(3, rng)
MsgBox cnt - 1 & " rows are visible"
End Sub

--
Regards,
Tom Ogilvy

"Peter" wrote:

I have written a code that will filters a sheet however I now need to
count the rows that come out of the filter. Is there any way to do
this?

Thanks,

Peter


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
Count all except filtered data andy62 Excel Discussion (Misc queries) 2 May 12th 09 07:43 PM
Count the Y's in a filtered column that contains Y and N TommyB Excel Worksheet Functions 1 July 11th 08 02:43 AM
Count Intervals of Filtered TEXT values in Column and Return Count across a Row Sam via OfficeKB.com Excel Worksheet Functions 9 July 31st 05 03:37 AM
Count filtered data only paulharvey[_3_] Excel Programming 1 July 18th 05 06:26 PM
Filtered Count Dean[_4_] Excel Programming 1 January 20th 05 05:45 AM


All times are GMT +1. The time now is 06:28 AM.

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

About Us

"It's about Microsoft Excel"