Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default How To Count Rows Displayed After Applying AutoFilter

I'm trying to write some VBA code to determine the number of rows being
displayed after applying a filter. This would be similar to what's
displayed in the lower left-hand corner of the Excel Window after applying a
filter. (Using the example below, it shows "4 of 10 records found")

Assume that I have 10 rows in a worksheet. After using AutoFilter to show
only rows without "ABC" in Col A and with "Closed" in Col B, I am looking
for a count of, say, 4. However, the code below always gives me the total
count of 10. That is, it ignores the applied filter.

Sub Macro()
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criticial:="<ABC", Operator:=xlAnd
Selection.AutoFilter Field:=2, Criterial:="Closed"
MsgBox Selection.CurrentRegion.Rows.Count
End Sub

Anyone know what code will give me the count of 4 I am looking for?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 422
Default How To Count Rows Displayed After Applying AutoFilter

The Subtotal() function works on Unhidden rows Only.
For Example, Subtotal(9,B1:B100) in B101 will sum only the Values in only
the Visible Rows
Subtotal(3,B1:B100) in B102 will count only the Visible Rows.
This of course is the function method of accomplishing, not the VBA although
you can incorporate the function in your code (I can't help with that)
perhaps someone else can,,,
HTH

"Steve" wrote in message
...
I'm trying to write some VBA code to determine the number of rows being
displayed after applying a filter. This would be similar to what's
displayed in the lower left-hand corner of the Excel Window after applying

a
filter. (Using the example below, it shows "4 of 10 records found")

Assume that I have 10 rows in a worksheet. After using AutoFilter to show
only rows without "ABC" in Col A and with "Closed" in Col B, I am looking
for a count of, say, 4. However, the code below always gives me the total
count of 10. That is, it ignores the applied filter.

Sub Macro()
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criticial:="<ABC", Operator:=xlAnd
Selection.AutoFilter Field:=2, Criterial:="Closed"
MsgBox Selection.CurrentRegion.Rows.Count
End Sub

Anyone know what code will give me the count of 4 I am looking for?




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
How to make list of Items displayed in AutoFilter? Any Function? Soham Excel Worksheet Functions 9 December 15th 09 11:12 AM
How do I count rows in a filtered list when using AutoFilter? chiefcook Excel Worksheet Functions 6 November 10th 08 09:21 AM
Counting the no. of entries after applying autofilter 1max Excel Discussion (Misc queries) 2 June 22nd 06 06:30 AM
Applying an AutoFilter to a string Hardip Excel Discussion (Misc queries) 3 April 16th 06 05:32 PM
Applying autofilter to protected sheet Brian Ferris Excel Discussion (Misc queries) 2 November 18th 05 04:28 PM


All times are GMT +1. The time now is 09:50 AM.

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"