Count number of rows populated by an autofilter in excel.

Saurabh k
Saurabh k used Ask the Experts™
on
team       subteam       user             priority
T              t2                       u1                1
T              t2                       u2                1
T              t2                       u2                1
T                 t2                       u2                1
T             t2                       u1                1
T            t2                       u1            1
T            t2                       u2                1
T             t2                       u1                1
T            t2                       u1                1
T              t2                       u2                1

consider above data I get by applying an autofilter for priority 1 for users u1,u2 belonging to team 2, what I need is a count of the populated rows in column ''priority'' in Excel VBA code. I tried using Subtotal function but I don't want the count generated via subtotal function.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Rob HensonFinance Analyst
Commented:
Why do you not want to use Subtotal function?

The syntax for subtotal is:

=SUBTOTAL(#,Range)

The # parameter has numerous options:
Function_num                   Function_num       Function
(includes hidden values)      (ignores hidden values)      
1                                    101                        AVERAGE
2                                    102                        COUNT
3                                    103                        COUNTA
4                                    104                        MAX
5                                    105                        MIN
6                                    106                        PRODUCT
7                                    107                        STDEV
8                                    108                        STDEVP
9                                    109                        SUM
10                                    110                        VAR
11                                    111                        VARP

Copied from the online help:

## If there are other subtotals within ref1, ref2,… (or nested subtotals), these nested subtotals are ignored to avoid double counting.

## For the function_num constants from 1 to 11, the SUBTOTAL function includes the values of rows hidden by the Hide Rows command under the Hide & Unhide submenu of the Format command in the Cells group on the Home tab in the Excel desktop application. Use these constants when you want to subtotal hidden and nonhidden numbers in a list. For the function_Num constants from 101 to 111, the SUBTOTAL function ignores values of rows hidden by the Hide Rows command. Use these constants when you want to subtotal only nonhidden numbers in a list.

## The SUBTOTAL function ignores any rows that are not included in the result of a filter, no matter which function_num value you use.

## The SUBTOTAL function is designed for columns of data, or vertical ranges. It is not designed for rows of data, or horizontal ranges. For example, when you subtotal a horizontal range using a function_num of 101 or greater, such as SUBTOTAL(109,B2:G2), hiding a column does not affect the subtotal. But, hiding a row in a subtotal of a vertical range does affect the subtotal.

## If any of the references are 3-D references, SUBTOTAL returns the #VALUE! error value.
Top Expert 2016
Commented:
Hi,

pls try
res  = Range("D1").End(xlDown).SpecialCells(xlCellTypeVisible).Rows.Count-1

Open in new window

REgards
Top Expert 2014
Commented:
activesheet.range(range("D2"),cells(rows.Count,4).end(xlup)).specialcells(XlCellType.xlCellTypeVisible).count

Open in new window

No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Split:
-- Rgonzo1971 (https:#a42399734)
-- aikimark (https:#a42401959)
-- Rob Henson (https:#a42399731)


If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

MacroShadow
Experts-Exchange Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial