The SUBTOTAL function in Excel is the best way to sum data while ignoring rows hidden by a filter, or to create a total that updates correctly when you hide rows manually. It is more flexible than a plain SUM because it lets you choose which calculation to run (sum, average, count, etc.) and it automatically skips filtered-out cells. You do not need any special setup to use it; just a column of numbers you want to add up.

What You'll Need

  • A worksheet with numeric values in a column (or multiple columns) that you want to sum.
  • Basic familiarity with typing formulas into a cell (starting with an equals sign).
  • Excel 2010 or later for the full function list; older versions still work but may have fewer function numbers.

Step-by-Step

  1. Decide where you want the total. Typically, you put the SUBTOTAL formula below the list of numbers, but you can place it anywhere. If you plan to filter the data, put the total in a row that will remain visible when filters are applied (often row 1 or a row above the data).
  2. Click the cell where you want the sum to appear.
  3. Type the formula. Start with an equals sign: =SUBTOTAL(
  4. Enter the function number. For a sum, use 9 if you want to include manually hidden rows, or 109 if you want to ignore rows you hide manually (both ignore filtered-out rows). Most people use 9 because it behaves like a normal SUM when no rows are hidden, and it still respects filters. So type =SUBTOTAL(9,
  5. Select the range you want to sum. You can click and drag to highlight the cells, or type the range like A2:A100. For example: =SUBTOTAL(9,A2:A100)
  6. Close the parenthesis and press Enter. The total appears.
  7. Test it with a filter. Select your data, go to the Data tab, and click Filter (or press Ctrl+Shift+L). Click the dropdown arrow in the column header, uncheck a few items, and watch your SUBTOTAL update. It will only sum the visible rows.
  8. Optional: use SUBTOTAL in multiple rows. If you have subtotals for each category and then a grand total, use SUBTOTAL for the grand total as well. That way, if you filter the list, the grand total will only sum the visible subtotals (since SUBTOTAL ignores other SUBTOTAL rows).

Common Mistakes

  • Using SUM instead of SUBTOTAL when filtering: A regular SUM will still add hidden rows after you filter, giving you a misleading total. SUBTOTAL is the correct choice.
  • Using the wrong function number: If you use 9 and then manually hide rows (by right-clicking a row and choosing Hide), those hidden rows will still be included. If you want to exclude manually hidden rows, use 109.
  • Including the SUBTOTAL cell in its own range: If your range includes the cell where you are typing the formula, you will get a circular reference error. Make sure the range stops above (or before) the formula cell.
  • Forgetting to close parentheses: Excel usually auto-corrects this, but if you type manually, a missing parenthesis will cause a syntax error.
  • Using SUBTOTAL on a range that already contains SUBTOTAL formulas: This is actually a feature (it ignores nested subtotals), but if you expected to sum those subtotals, you might get a smaller number than expected. Use a regular SUM for that specific case.

Tips

  • Use the Function Library: Instead of typing the function number from memory, go to the Formulas tab > More Functions > Statistical (or Math & Trig) > SUBTOTAL. Excel will show a dialog where you can pick the function (Sum, Average, etc.) and the reference. This reduces errors.
  • Remember the function numbers: For sum, it's 9 (or 109). For average, 1 (or 101). For count, 2 (or 102). For max, 4 (or 104). For min, 5 (or 105). The numbers 1-11 include manually hidden rows; 101-111 ignore them.
  • Combine with a table: If you convert your data to an Excel Table (Ctrl+T), you can add a Total Row from the Table Design tab. That row uses SUBTOTAL automatically, and it updates when you filter the table.
  • Use SUBTOTAL for dynamic ranges: If you add rows to the end of your data, the SUBTOTAL range will not expand automatically unless you use a Table or a named range. Consider using a Table to make the range dynamic.
  • Hide rows vs. filter: If you hide rows manually (right-click > Hide), SUBTOTAL with 9 will still include them. If you want to exclude them, use 109. If you filter, both 9 and 109 exclude filtered rows.

Troubleshooting

  1. Subtotal shows 0: Check that the range contains numbers, not text. If cells are formatted as text, use the Text to Columns wizard (Data tab) to convert them. Also, ensure the cells are not empty or full of spaces.
  2. Subtotal does not update when filtering: Make sure you are using the Filter command (Data > Filter) and not just hiding rows. If you manually hide rows, SUBTOTAL with 9 will not change. Switch to 109 if you want that behavior.
  3. Circular reference warning: Your SUBTOTAL range includes the cell with the formula. Adjust the range to exclude that cell. For example, if your formula is in A101, use A2:A100.
  4. Subtotal returns #VALUE!: This usually means the range includes text that cannot be coerced to a number. Check for non-numeric characters like commas or currency symbols. Use the VALUE function or clean the data.
  5. Subtotal is not ignoring other subtotals: That is by design. SUBTOTAL ignores other SUBTOTAL formulas, so if you have a grand total that is not updating as expected, use a regular SUM for that grand total.

Frequently Asked Questions

What is the difference between SUBTOTAL(9) and SUBTOTAL(109)?

Both ignore rows hidden by a filter. The difference is how they treat rows you hide manually (right-click > Hide). SUBTOTAL(9) includes manually hidden rows; SUBTOTAL(109) excludes them. For most users, 9 is fine because it behaves like a normal SUM when no rows are hidden.

Can I use SUBTOTAL to count cells instead of summing?

Yes. Use function number 2 (or 102) for counting numbers, or 3 (or 103) for counting non-empty cells. For example, =SUBTOTAL(3,A2:A100) counts how many cells have any value.

Does SUBTOTAL work with Excel tables?

Yes. When you add a Total Row to an Excel Table, Excel automatically uses SUBTOTAL (usually 109) for the total. It updates when you filter the table.

Why does my SUBTOTAL formula show a different result than SUM?

Because SUBTOTAL ignores rows hidden by a filter (and optionally manually hidden rows), while SUM includes all rows. If you have no hidden rows, they should return the same value.

Can I use SUBTOTAL on multiple columns at once?

Yes. You can reference multiple ranges separated by commas, like =SUBTOTAL(9,A2:A10,C2:C10). However, note that SUBTOTAL will sum all the values in those ranges, not separate totals per column.

Does SUBTOTAL work in Google Sheets?

Yes, Google Sheets has the same SUBTOTAL function with the same function numbers. The steps are identical.