Sum Visible Rows

When you’ve filtered data in Excel, the SUM function still sums cells even if they’re not visible. To SUM only the visible data, you can use the SUBTOTAL function. SUBTOTAL ignores hidden rows and columns.

In this example, there are 2156 rows of data that are filtered so that only those rows whose City is ‘Paris’ are shown.

subtotal

The formulas below the filtered data are:
C2159 - =SUM(C2:C2157)
D2159 - =SUM(D2:D2157)
C2160 - =SUBTOTAL(9,C2:C2157)
D2160 - =SUBTOTAL(9,D2:D2157)

You can do more than just sum with SUBTOTAL. The first argument (9) is what tells SUBTOTAL to sum. Look up SUBTOTAL_worksheet_function in help to see the other possible arguments.

6 Comments

  1. Peter:

    Interestingly, the subtotal function only works this way with “filtered” lists, and continues to sum rows which are just “hidden”.

  2. Juan Pablo:

    Peter,

    That is one of the new features in Excel 2003. They introduced new parameters to fix that issue.

  3. Ana:

    Hi,

    And how do we do this in a Macro?
    How do I navigate between the visible rows only?

    Thanks in advance,
    A.

  4. excelerater:

    in excel 2202, i entered the following

    a1 = subtotal(9,a:a)
    a2 = data autofilter
    a3 = data


    a99 = data

    it worked when i first created it, to automatically
    add up the visible data that was filtered by the
    autofilter.
    now it stopped working and complains about a circular reference. the “subtotal” function is suppose to be smart enough to ignore other subtotals so values are not double counted.
    i want the total at the top, so that it is always visible and so that i can add more data at the bottom

    anyone have any ideas?

  5. Patrick Sedgwick:

    I had this problem with hidden (as distinct from hidden-after-filtering) rows. Microsoft have a solution:
    http://support.microsoft.com/?kbid=150363

  6. Mohammed:

    Thank you! Saved few hours of my time today.

Leave a comment