简体   繁体   中英

Excel: How to Count TRUE in Filtered “Named Ranges”

After doing a long search, I have yet to find an answer. I feel like I am asking something so out of the ordinary, like "How do you count unicorns?"

So here it goes:

How do you in Excel... count the number of TRUE cells in a FILTERED "named range"?

I found one that will work with specifying the Column - Row Index like A2:A100.

=SUMPRODUCT(SUBTOTAL(3,OFFSET(A2:A100,ROW(A2:A100)-MIN(ROW(A2:A100)),,1)), --(A2:A100=TRUE))

That doesn't work for me. Got to be Named Ranges. I can't use a helper column either. I'd rather not use VBA. And... there is one more request for some additional magical powers: My named range is the whole column, headers and all. works with SUBTOTAL anyway.

What version of Excel are you using? In 2013, I am able to make this work properly.

I populated A2:A100 with 50 TRUE and 49 FALSE values and B2:B100 with 99 RAND() values. I then filtered on various number filters in column B and all of the below formulas worked properly, counting only the visible TRUE values in column A.

Example 1: Original Formula

=SUMPRODUCT(SUBTOTAL(3,OFFSET(A2:A100,ROW(A2:A100)-MIN(ROW(A2:A100)),,1)), --(A2:A100=TRUE))

Example 2: Non-Dynamic Exact Named Range

Range named "NonDynamic" and set to:

=Sheet1!$A$2:$A$100

Formula:

=SUMPRODUCT(SUBTOTAL(3,OFFSET(NonDynamic,ROW(NonDynamic)-MIN(ROW(NonDynamic)),,1)), --(NonDynamic=TRUE))

Example 3: Dynamic Named Range

Range named "Dynamic" and set to:

=OFFSET(Sheet1!$A$1,1,0,COUNTA(Sheet1!$A:$A)-1)

Formula:

=SUMPRODUCT(SUBTOTAL(3,OFFSET(Dynamic,ROW(Dynamic)-MIN(ROW(Dynamic)),,1)), --(Dynamic=TRUE))

Note: is a dynamic named range an option for you? They are often significantly more efficient than referencing an entire column, especially if there are no blank values in the column between the first and last row of data.

Example 4: Non-Dynamic Named Range of Entire Column

Range named "WholeColumn" and set to:

=Sheet1!$A:$A

Formula:

=SUMPRODUCT(SUBTOTAL(3,OFFSET(WholeColumn,ROW(WholeColumn)-MIN(ROW(WholeColumn)),,1)), --(WholeColumn=TRUE))

All four examples produce the exact same results in Excel 2013. For example, I filtered on column B > 0.5; this left 26 TRUE values visible of 50 total. All four formulas changed from 50 to 26.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM