+ Reply to Thread
Results 1 to 3 of 3

Count filtered cells using SUBTOTAL

  1. #1
    Forum Contributor Russell Dawson's Avatar
    Join Date
    03-01-2012
    Location
    Yorkshire, England
    MS-Off Ver
    2007
    Posts
    608

    Count filtered cells using SUBTOTAL

    Here's what might be one of the most versatile formulae in (almost) common usage.

    I made a similar posting in March but only from a COUNTA point of view. This attempts to expand that to most of the available options.

    SUBTOTAL uses a selection of "subservient" commands to achieve the goal.

    Those commands are: 1 - AVERAGE, 2 - COUNT, 3 - COUNTA, 4 - MAX, 5 - MIN,
    6 - PRODUCT, 7 - STDEV, 8 - STDEVP, 9 - SUM, 10 - VAR, 11 – VARP

    All are formulae in their own right but used within SUBTOTAL allows for filtered lists to be worked with.

    Basically, the formula only works with what you can see when a filter has been applied.

    I'm really promoting the SUBTOTAL formula and knowledge of the secondary formulae is not paramount in this description although users with better knowledge of the more obscure (to me) statistical formula such as STDEV, STDEVP, VAR and VARP will no doubt recognise the benefits themselves.

    I have prepared a small table containing data on customers on the attached workbook. It could be hundreds of rows. Let’s say for example that we need to know how many unmarried females in the 21-30 age group there are. Very useful IMO! Make the appropriate filters to columns B & C and the formula will only count the number of entries returned.

    In this example I have chosen 3 (COUNTA) which simply counts entries in non blank cells in the range.

    =SUBTOTAL(3,D2:D10)

    The syntax is:

    =SUBTOTAL(TYPE OF TOTAL, RANGE OF CELLS)

    The same principle applies to the others, find the average, find the min/max, sum etc for the filtered data you request. It's very versatile.

    Some of the formulae in the worksheet have had IF statements added to avoid errors appearing – (just for demo)

    A note of caution – when constructing your worksheet ensure that your cells containing the SUBTOTAL formula and therefore your results are not on the same rows as the range of data. I prefer to put it above the top of the range.

    So, there you have it. SUBTOTAL an unusual and clever formula.
    Attached Files Attached Files
    If I helped, please don't forget to add to my reputation. (click on the star below the post)

    If the problem is solved, please: Select Thread Tools (on top of your 1st post) -> Mark this thread as Solved.

    Failure is not falling down but refusing to get up.

  2. #2
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Count filtered cells using SUBTOTAL

    SUBTOTAL() has been improved upon for Excel 2010+ with the introduction of the AGGREGATE() function.

    http://www.excelfunctions.net/Excel-...-Function.html

  3. #3
    Registered User
    Join Date
    07-08-2012
    Location
    Aurangabad, Maharashtra
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: Count filtered cells using SUBTOTAL

    Nice. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1