Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Count all except filtered data | Excel Discussion (Misc queries) | |||
Count the Y's in a filtered column that contains Y and N | Excel Worksheet Functions | |||
Count Intervals of Filtered TEXT values in Column and Return Count across a Row | Excel Worksheet Functions | |||
Count filtered data only | Excel Programming | |||
Filtered Count | Excel Programming |