Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel SUBTOTAL Formula for Filtered Data

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Yes, the SUBTOTAL function is the correct way to sum, count, or average only the visible rows in a filtered Excel list. Unlike SUM, SUBTOTAL ignores rows hidden by a filter (and optionally rows you hide manually). You’ll use it like =SUBTOTAL(9, A2:A100) where 9 means SUM — the function number changes what operation it performs. You don’t need any add-ins or special setup, just a data range with column headers.

What You'll Need

  • A worksheet with data in a contiguous range (no blank rows or columns inside the data).
  • Column headers in the first row of that range.
  • Excel 2010 or newer for the full set of SUBTOTAL function numbers (older versions still have the basics).

Step-by-Step

  1. Identify your data range — note the first and last cell references, e.g., A2:C100 if row 1 has headers and data ends at row 100.
  2. Click the cell where you want the result — usually below the data or to the right of it. For example, click D101 if your data ends at row 100.
  3. Type the formula — start with =SUBTOTAL(. Excel will show a dropdown of function numbers. Choose 9 for SUM, 2 for COUNT, 3 for COUNTA, 1 for AVERAGE, 4 for MAX, 5 for MIN. (The numbers 101–111 do the same but also ignore manually hidden rows.)
  4. Select the range — after the comma, select the column of numbers you want to aggregate, e.g., B2:B100. Close the parenthesis and press Enter.
  5. Test it — apply a filter by clicking Data > Filter (or Home > Sort & Filter > Filter). Use the dropdown arrows on your headers to filter for a specific value. The SUBTOTAL result updates to only show the visible rows.
  6. Copy the formula for other columns — if you need sums for multiple numeric columns, copy the formula across to the right. Each one should reference its own column range.
  7. Add a total row if you prefer — instead of typing the formula manually, you can convert your data to an Excel Table (select the data, press Ctrl+T), then check the “Total Row” box on the Table Design tab. The total row uses SUBTOTAL automatically and updates when you filter.

Common Mistakes

  • Using SUM instead of SUBTOTAL — SUM always adds all rows, even hidden ones. That defeats the purpose.
  • Wrong function number — 9 is sum, but 109 is also sum (ignores manually hidden rows). If you use 1 (average) when you wanted a sum, you’ll get a wrong result.
  • Including the header row in the range — if your range includes text, SUBTOTAL will return an error for numeric operations. Always start at the first data row.
  • Blank rows or columns inside the data — these break the filter and can cause SUBTOTAL to reference the wrong range. Keep your data contiguous.
  • Forgetting to refresh after changing filters — normally SUBTOTAL recalculates automatically, but if your sheet is set to manual calculation, you’ll need to press F9.

Tips

  • Use function numbers 101–111 (e.g., 109 for sum) if you also hide rows manually (right-click > Hide) and want those hidden rows ignored too. Regular numbers 1–11 only ignore rows hidden by a filter.
  • If you have multiple subtotals (e.g., sum and count), you can put them in separate cells and reference the same range.
  • For a quick subtotal without typing, select your data, press Alt+= (or click the AutoSum button) — but note that AutoSum inserts SUM, not SUBTOTAL. You’ll need to change it manually to SUBTOTAL.
  • When using an Excel Table, the Total Row is the easiest way — it automatically uses SUBTOTAL and you can toggle each column’s function from its dropdown.
  • If you need to subtotal by category (e.g., sum per department), use the Subtotal command under Data > Subtotal (not the function) — but that’s for a different purpose and requires sorted data.

Troubleshooting

If the result doesn’t change when you filter:

  1. Check that you actually applied a filter (the row numbers should turn blue and dropdown arrows appear).
  2. Make sure the formula range covers only the data column, not the entire column (e.g., B:B is okay, but if you have stray numbers below your data, they’ll be included).
  3. Verify you used SUBTOTAL, not SUM. Look at the formula bar.
  4. Press Ctrl+Alt+F9 to force a full recalculation in case calculation is set to manual.

If you get a #VALUE! error:

  • Your range includes text or blank cells in a column that expects numbers. For SUM, blanks are fine, but text will cause an error. Adjust the range to only numeric cells.

If the subtotal shows 0 when it shouldn’t:

  • Check that the cells are formatted as numbers, not text. Select the cells, look for a green triangle warning, and convert text to numbers using the error icon.

If you want to exclude manually hidden rows but it’s not working:

  • You’re using function numbers 1–11. Switch to 101–111 (e.g., 109 for sum).

Frequently Asked Questions

What’s the difference between SUBTOTAL(9) and SUBTOTAL(109)?

Both sum visible rows, but 109 also ignores rows you hide manually (right-click > Hide). 9 only ignores rows hidden by a filter. If you never hide rows manually, they behave the same.

Can I use SUBTOTAL with multiple columns at once?

No, each SUBTOTAL function works on a single range. But you can write separate SUBTOTAL formulas for each column, or use an Excel Table’s Total Row which does this automatically.

Does SUBTOTAL work with filtered data in Excel Online or Google Sheets?

Yes, SUBTOTAL works in Excel Online. In Google Sheets, the equivalent is SUBTOTAL as well, but the function numbers are the same (9 for sum, 109 for sum ignoring manually hidden rows).

Why does my SUBTOTAL formula return the same as SUM even when I filter?

That usually means you’re not actually filtering — maybe the filter is applied to a different range, or you have a table that isn’t filtering correctly. Check that the row numbers are blue and the dropdown arrows are visible.

Can I use SUBTOTAL inside another formula like IF?

Yes, SUBTOTAL can be nested, but it’s tricky because SUBTOTAL returns a single value. For conditional sums on filtered data, you’d typically use SUMPRODUCT with SUBTOTAL and OFFSET, which is advanced. For most cases, a simple SUBTOTAL is enough.

Does SUBTOTAL ignore rows hidden by grouping (outline) or by filtering?

SUBTOTAL with numbers 1–11 ignores rows hidden by filtering. For rows hidden by grouping (outlining), you need to use 101–111 numbers to ignore those as well, because grouping hides rows in a different way.