Link to home
Start Free TrialLog in
Avatar of kosenrufu
kosenrufu

asked on

What is the Excel VBA to count number of rows in a filtered range?

What is the Excel VBA to count number of rows in a filtered range?

Thanks
Avatar of moonlightallan
moonlightallan

Hope this helps!

"When you have selected a range, it is sometimes useful to know how many rows or columns you have selected as this information can be used in your macros (for eg when you have reached the end, you will know it is time to stop the macros":

Sub Count()
myCount = Selection.Rows.Count    'Change Rows to Columns to count columns
MsgBox myCount
End Sub

http://www.angelfire.com/biz7/julian_s/julian/julians_macros.htm
ASKER CERTIFIED SOLUTION
Avatar of Tracy
Tracy
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
How about for a range in question of D5 thru D1400:

msgbox WorksheetFunction.Subtotal(3, Range("d5:d1400"))

Of course, you could always use the Subtotal worksheet function right in the worksheet.  You don't really need VBA.  The Subtotal function can also give you average, min, max, count, counta, sum of the visible rows in a filtered range.