The subtotal number formula in Excel is =SUBTOTAL(function_num, range), where function_num is a code (1–11 or 101–111) that tells Excel which calculation to perform, and range is the cells to include. For example, =SUBTOTAL(9, A2:A10) sums the visible cells in A2:A10, ignoring rows hidden by a filter.
What the Function Numbers Mean
The SUBTOTAL function uses a numeric code to select the operation. The codes 1–11 include manually hidden rows, while 101–111 ignore rows hidden manually (right-click > Hide). Both sets ignore rows hidden by a filter. The full list:
- 1 / 101 – AVERAGE
- 2 / 102 – COUNT
- 3 / 103 – COUNTA
- 4 / 104 – MAX
- 5 / 105 – MIN
- 6 / 106 – PRODUCT
- 7 / 107 – STDEV.S (sample standard deviation)
- 8 / 108 – STDEV.P (population standard deviation)
- 9 / 109 – SUM
- 10 / 110 – VAR.S (sample variance)
- 11 / 111 – VAR.P (population variance)
So =SUBTOTAL(9, C2:C50) sums the visible cells in C2:C50 after filtering. If you use 109, it also ignores rows you hid manually.
How to Use SUBTOTAL Step by Step
To get a subtotal that updates when you filter or hide rows:
- Select the cell where you want the result.
- Type
=SUBTOTAL(– Excel will show a drop-down list of function numbers. - Enter the number for the operation (e.g., 9 for SUM) followed by a comma.
- Select the range of cells to include (e.g.,
B2:B100). - Close the parenthesis and press Enter.
Example: With sales amounts in B2:B100, =SUBTOTAL(9, B2:B100) returns the sum of visible sales. If you filter to show only one region, the formula recalculates to show only that region’s total.
Why Use SUBTOTAL Instead of SUM or AVERAGE?
The main advantage is that SUBTOTAL ignores rows hidden by a filter. A regular =SUM(B2:B100) still adds all cells, even filtered-out rows. SUBTOTAL also ignores other SUBTOTAL formulas inside its range, which prevents double-counting when you have nested subtotals (like in a data outline). This makes it ideal for reports where you filter data frequently or use Excel’s Group feature to collapse sections.
Another benefit: the 101–111 codes let you choose whether to ignore manually hidden rows. If you hide a row by right-clicking, a SUM would still include it; SUBTOTAL with 109 would exclude it.
Common Problems and How to Fix Them
Here are frequent issues users run into:
- Wrong result after filtering: Make sure you used a code 1–11 or 101–111, not a plain SUM. If you used 9, it ignores filtered rows, but not manually hidden rows. Switch to 109 if you need both.
- Subtotal includes hidden rows unexpectedly: Check if you used a code 1–11. For example, 9 sums all rows, even manually hidden ones. Use 109 to exclude them.
- Formula returns 0: Check that the range contains numbers and that you didn’t accidentally reference empty cells. Also ensure the cells aren’t formatted as text.
- Nested subtotals double count: SUBTOTAL ignores other SUBTOTAL formulas, so this shouldn’t happen. If you see double counting, you might have used SUM inside a range that contains another SUBTOTAL.
Using the Subtotal Command (Data Tab)
Excel also has a built-in command that inserts SUBTOTAL formulas automatically. Go to Data > Outline > Subtotal. This works best when your data is sorted by a column. Steps:
- Sort your data by the column you want to group by (e.g., Region).
- Click anywhere in your data range.
- Go to Data > Outline > Subtotal.
- In the dialog, choose the column to group by (e.g., Region), the function (e.g., Sum), and the column to subtotal (e.g., Sales).
- Click OK. Excel inserts SUBTOTAL formulas and outline buttons.
This is handy for quick reports, but note that the command uses the 9/109-style codes depending on your settings. It also adds a grand total row at the bottom.
SUBTOTAL vs. AGGREGATE
Excel’s AGGREGATE function is a more powerful alternative. It also ignores hidden rows and can ignore error values. Syntax: =AGGREGATE(function_num, options, array). For example, =AGGREGATE(9, 5, B2:B100) sums visible cells and ignores error values. The options argument (1–7) lets you choose what to ignore (hidden rows, errors, etc.). AGGREGATE supports more functions (like MEDIAN and LARGE) than SUBTOTAL. Use SUBTOTAL for simple filtered sums; use AGGREGATE when you need error handling or functions not in SUBTOTAL’s list.
Frequently Asked Questions
What is the difference between SUBTOTAL(9) and SUBTOTAL(109)?
Both sum visible cells after filtering. The difference is that 109 also ignores rows you hide manually (right-click > Hide). 9 includes manually hidden rows. So if you hide a row by hand, SUBTOTAL(9) still counts it; SUBTOTAL(109) does not.
Can I use SUBTOTAL on multiple ranges?
Yes, you can list multiple ranges separated by commas, like =SUBTOTAL(9, A2:A10, C2:C10). However, if you have multiple ranges, they must be in the same worksheet. You cannot use a 3D reference (like across sheets) with SUBTOTAL.
Why does my SUBTOTAL formula show a #VALUE! error?
This usually happens if you use a function number that isn’t valid (e.g., 0 or 12) or if the range contains errors. For example, if a cell in the range has #DIV/0!, SUBTOTAL will return that error unless you use AGGREGATE with the appropriate option.
Does SUBTOTAL work in Google Sheets?
Yes, Google Sheets has the same SUBTOTAL function with identical codes. The behavior is similar, but the Data > Subtotal command is not available in Google Sheets; you must type the formula manually.
Can I use SUBTOTAL in a pivot table?
No, SUBTOTAL is not meant for pivot tables. Pivot tables have their own subtotal feature (right-click a field > Field Settings > Subtotals & Filters). Using SUBTOTAL inside a pivot table can cause errors or unexpected results.
Keyboard Shortcuts and Mac Notes
On Windows, press Alt + = to insert a SUM quickly, but that gives a regular SUM, not SUBTOTAL. To insert SUBTOTAL quickly, you can type =SUBTOTAL( and use the arrow keys to select the function number from the list. On Mac, the shortcut is Command + Shift + T to insert a SUM, but again, that’s not SUBTOTAL. The SUBTOTAL function works the same on Mac, but the Data > Subtotal command is under Data > Outline > Subtotal (same as Windows).
Related
- By Means of an Update? Meaning & Real Usage
- Windows Ctrl Shortcuts: The Complete List
- Speed and Intersection Safety Cameras: How They Work
Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.
More in Formulas & functions
- Copy Formulas in Excel to a New Sheet Without ErrorsTo copy formulas to a new sheet in Excel, select the formula cells, press Ctrl+C, open the destination…
- SUMIF Criteria Examples: Text, Dates, Numbers, and MoreIn Excel, SUMIF adds values that match one condition; for example, with categories in A2:A7 and amounts in…
- Python split() Function: How to Split Strings with ExamplesUse Python’s string method split() to turn one string into a list of smaller strings. Call text.split() to…
- Sort an Excel Column Highest to Lowest: Quick StepsTo sort numbers in Excel from highest to lowest, select a cell in the column and choose Data…
- SQL Server String Functions and How to Use ThemSQL Server string functions let you measure, search, extract, combine, replace, and format text in a query. Common…
- Excel Formula for Variance Between Two CellsTo calculate the difference between two cells in Excel, subtract one from the other: with the earlier or…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.