Menu

SUBTOTAL in Excel: Totals That Skip Subtotals and Filters

=SUBTOTAL(9,C2:C8) adds C2:C8 like SUM but ignores other SUBTOTAL rows inside the range and rows hidden by a filter. Function numbers 9 and 109, counting visible rows, and AGGREGATE for errors.

Every sheet on this page is live: change a number or a formula and it recalculates.

=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.

Subtotals and a grand total
C8
ABCDEF
1RegionItemSalesCheckResult
2NorthApple120SUM of C2:C7890
3NorthPear80
4North total200
5SouthApple200
6SouthPear45
7South total245
8Grand total445
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

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], ...)
CalculationSkips filtered rowsAlso skips rows hidden by hand
AVERAGE1101
COUNT (numbers)2102
COUNTA (non-empty)3103
MAX4104
MIN5105
PRODUCT6106
STDEV.S7107
STDEV.P8108
SUM9109
VAR.S10110
VAR.P11111

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.

Other calculations
F2
ABCDEF
1RegionItemSalesCalculationResult
2NorthApple120AVERAGE (1)88.33
3NorthPear80COUNTA (3)6
4SouthApple200MAX (4)200
5SouthPear45MIN (5)30
6EastApple55Visible rows (103)6
7EastPlum30SUM (109)530
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

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.

Skip an error
F3
ABCDEF
1RegionItemSalesFormulaResult
2NorthApple120SUBTOTAL#N/A
3NorthPear#N/AAGGREGATE, ignore errors450
4SouthApple200AGGREGATE, MAX200
5SouthPear45
6EastApple55
7EastPlum30
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

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

Your turn: grand total
C9
ABC
1RegionItemSales
2NorthApple120
3NorthPear80
4North total200
5SouthApple200
6SouthPear45
7SouthPlum60
8South total305
9Grand total
Click a cell to see its formula. Change a number or a formula and the sheet recalculates.

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.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED