=SUBTOTAL(9,C2:C8) adds the numbers in C2:C8, like SUM, with two differences: it skips any other SUBTOTAL formula inside the range, and it skips rows hidden by a filter. The first argument, 9, says which calculation to do.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Region | Item | Sales | Check | Result | |
| 2 | North | Apple | 120 | SUM of C2:C7 | 890 | |
| 3 | North | Pear | 80 | |||
| 4 | North total | 200 | ||||
| 5 | South | Apple | 200 | |||
| 6 | South | Pear | 45 | |||
| 7 | South total | 245 | ||||
| 8 | Grand total | 445 |
The grand total in C8 runs over the whole column, the subtotal rows included, and still shows 445: SUBTOTAL leaves out C4 and C7 because they hold SUBTOTAL formulas. F2 does the same with SUM and shows 890, every sale counted twice. With SUBTOTAL on every total row you can add or move groups without rewriting the grand total.
SUBTOTAL function numbers
=SUBTOTAL(function_num, ref1, [ref2], ...)
| Calculation | Skips filtered rows | Also skips rows hidden by hand |
|---|---|---|
| AVERAGE | 1 | 101 |
| COUNT (numbers) | 2 | 102 |
| COUNTA (non-empty) | 3 | 103 |
| MAX | 4 | 104 |
| MIN | 5 | 105 |
| PRODUCT | 6 | 106 |
| STDEV.S | 7 | 107 |
| STDEV.P | 8 | 108 |
| SUM | 9 | 109 |
| VAR.S | 10 | 110 |
| VAR.P | 11 | 111 |
When you type =SUBTOTAL(, Excel shows this list, so you do not need to memorize it. 9 and 109 (SUM), 1 (AVERAGE) and 103 (count visible rows) are the ones used most.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Region | Item | Sales | Calculation | Result | |
| 2 | North | Apple | 120 | AVERAGE (1) | 88.33 | |
| 3 | North | Pear | 80 | COUNTA (3) | 6 | |
| 4 | South | Apple | 200 | MAX (4) | 200 | |
| 5 | South | Pear | 45 | MIN (5) | 30 | |
| 6 | East | Apple | 55 | Visible rows (103) | 6 | |
| 7 | East | Plum | 30 | SUM (109) | 530 |
Nothing is hidden here, so each line equals the ordinary function: an average of 88.33, 6 rows, a MAX of 200, a MIN of 30 and a SUM of 530. The difference shows only when rows are hidden, which is what the next section is about.
SUBTOTAL 9 vs 109, and filtered rows
Turn on a filter with Data > Filter (Ctrl+Shift+L, Cmd+Shift+F on a Mac), then pick North in the Region drop-down. Rows of other regions are hidden:
=SUM(C2:C7)still adds all six rows.=SUBTOTAL(9,C2:C7)and=SUBTOTAL(109,C2:C7)add only the visible North rows.=SUBTOTAL(103,A2:A7)counts the rows left on screen: 2, the same number as "2 of 6 records found" in the status bar.
The two families differ only for rows you hide by hand (select rows, right-click > Hide). 9 still adds those; 109 does not. If the total should always match what is on screen, use 109. If you hide rows only to tidy the view and still want them in the total, use 9.
SUBTOTAL works on rows only. Hidden columns are always included, so =SUBTOTAL(109,B2:G2) across a row adds hidden columns too.
The quickest way to get a SUBTOTAL is the AutoSum button with a filter on: Excel writes =SUBTOTAL(9,...) instead of SUM. Data > Subtotal goes further: on a list sorted by a column, it inserts a total row under each group and a grand total, all with SUBTOTAL, plus outline buttons to collapse the groups.
AGGREGATE: SUBTOTAL that can skip errors
If one cell in the range holds an error, SUM and SUBTOTAL return that error. AGGREGATE (Excel 2010 and later) is SUBTOTAL with an extra options argument; option 6 ignores error values.
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Region | Item | Sales | Formula | Result | |
| 2 | North | Apple | 120 | SUBTOTAL | #N/A | |
| 3 | North | Pear | #N/A | AGGREGATE, ignore errors | 450 | |
| 4 | South | Apple | 200 | AGGREGATE, MAX | 200 | |
| 5 | South | Pear | 45 | |||
| 6 | East | Apple | 55 | |||
| 7 | East | Plum | 30 |
C3 holds #N/A, so F2 shows #N/A too. F3 ignores it and adds the other five: 450. Its first argument uses the same numbers as SUBTOTAL (9 is SUM, 4 is MAX). Other options: 5 ignores hidden rows, 7 ignores hidden rows and errors, 3 ignores hidden rows, errors and nested SUBTOTAL and AGGREGATE formulas. Replace C3 with a number and F2 shows the same total as F3.
Practice: a grand total over subtotals
| A | B | C | |
|---|---|---|---|
| 1 | Region | Item | Sales |
| 2 | North | Apple | 120 |
| 3 | North | Pear | 80 |
| 4 | North total | 200 | |
| 5 | South | Apple | 200 |
| 6 | South | Pear | 45 |
| 7 | South | Plum | 60 |
| 8 | South total | 305 | |
| 9 | Grand total |
Your turn: The list has a subtotal under each region. Put a grand total in C9 that covers C2:C8 without counting the subtotal rows twice.
Why a SUBTOTAL total is still wrong
- The group totals use SUM. SUBTOTAL skips other SUBTOTAL formulas inside its range, not SUM formulas. A group total written as
=SUM(C2:C3)is counted again. Change every total row to SUBTOTAL. - The rows were hidden by hand and the function number is 9. Use 109.
- The data is in columns, not rows. Hidden columns are never skipped.
- You need a condition, not a filter. SUBTOTAL follows what the filter hides. To total North without filtering, use SUMIF. For a summary of every group at once, a pivot table does it without total rows in the data.
Frequently Asked Questions
What does SUBTOTAL 9 mean in Excel?
The first argument picks the calculation, and 9 is SUM. =SUBTOTAL(9,C2:C8) adds C2:C8, skipping rows hidden by a filter and any other SUBTOTAL formulas in the range. 1 is AVERAGE, 2 COUNT, 3 COUNTA, 4 MAX, 5 MIN.
What is the difference between SUBTOTAL 9 and 109?
Both skip rows hidden by a filter. 109 also skips rows you hid by hand (right-click > Hide), while 9 still adds them. Use 109 when the total should match exactly what is on screen.
How do I sum only the visible cells after filtering?
Use =SUBTOTAL(9,C2:C100) or =SUBTOTAL(109,C2:C100) under the data. When you filter the list, the total changes to the visible rows only. A plain SUM keeps adding the hidden rows.
How do I count visible rows in a filtered list?
Use =SUBTOTAL(103,A2:A100). 103 is COUNTA that skips hidden rows, so it counts the filled cells that are still on screen.
How do I sum a range that contains errors?
Use AGGREGATE with option 6, ignore errors: =AGGREGATE(9,6,C2:C8). SUM and SUBTOTAL both return the error if one cell in the range holds #N/A.