To subtotal only visible cells in Excel—such as after applying an AutoFilter—you use the SUBTOTAL function with a specific function number that ignores hidden rows. Unlike SUM, SUBTOTAL automatically skips filtered-out data, but only if the rows are hidden by filtering (not manual hiding unless using the correct function codes). This ensures accurate totals in filtered reports without manual adjustments.
What You'll Need
- Microsoft Excel (any modern version: Microsoft 365, Excel 2021, 2019, 2016, or Excel for the web)
- A dataset with column headers and at least one column of numeric values to subtotal
- Filtered data (via Data > Filter or Ctrl+Shift+L)
Step-by-Step
- Prepare your data: Ensure your dataset is in a contiguous table (no blank rows/columns within the data range) and has clear headers in the first row. Select any cell in your data, then press Ctrl+T (or Ctrl+Shift+L) to apply AutoFilter if not already enabled.
- Apply a filter: Click the drop-down arrow in a column header (e.g., a "Category" or "Status" column), then select criteria to hide certain rows (e.g., uncheck "Pending" to hide those rows). Only visible rows remain displayed.
- Identify the column to subtotal: Decide which numeric column you want to subtotal (e.g., "Sales" in column D). Note its column letter (e.g., D).
- Enter the SUBTOTAL formula: Click the cell where you want the total (e.g., below the last data row in column D). Type
=SUBTOTAL(. Excel will show a list of function numbers: use 9 forSUMthat ignores hidden rows, or 109 forSUMthat ignores *both* hidden rows and rows hidden by manual hiding. For this guide, we use 9 (visible-only after filtering):=SUBTOTAL(9,D2:D100). Adjust the range (e.g., D2:D100) to cover your actual data range—exclude headers, include only the numeric column. - Confirm the formula: Press Enter. The result updates automatically when you change the filter criteria. For example, if you filter to show only "Shipped" orders, the subtotal reflects only those rows’ sales values.
- Apply to other columns: Repeat step 4 for other numeric columns (e.g.,
=SUBTOTAL(9,E2:E100)for Quantity). Ensure each SUBTOTAL uses the correct column reference and consistent range. - Verify with a simple test: Temporarily hide a row manually by right-clicking it > Hide. Your SUBTOTAL (with function 9) should remain unchanged, confirming it ignores manually hidden rows. Now apply a filter to hide rows—your subtotal should update, proving it responds to filtered (not manual) hiding when using function 9.
Common Mistakes
- Using SUM instead of SUBTOTAL:
=SUM(D2:D100)includes hidden rows and gives incorrect totals after filtering. Always replace SUM with SUBTOTAL for filtered data. - Incorrect function number: Using 1–8 (e.g., 1 for AVERAGE) instead of 9 or 109 gives averages, counts, etc., but may not match your intent. For summation, stick to 9 (visible after filter) or 109 (visible after filter + manual hide).
- Including headers in the range: Writing
=SUBTOTAL(9,D1:D100)when D1 is a header causes errors or #VALUE! if text is in the column. Always start from the first data row (e.g., D2). - Non-contiguous ranges: SUBTOTAL does not support disjoint ranges like
D2:D50,F2:F50. Keep ranges single-column and contiguous. - Assuming manual hide affects SUBTOTAL(9): Function 9 only ignores rows hidden by AutoFilter. Rows hidden manually (right-click > Hide) are *included*. Use function 109 if you need to ignore both filter hiding and manual hiding.
Tips
- Use Excel Tables: Convert your data to a Table (Ctrl+T), then use structured references like
=SUBTOTAL(9,Table1[Sales]). This auto-adjusts when rows are added. - Copy-paste with care: When copying SUBTOTAL formulas, verify the column reference updates correctly (e.g., D2:D100 → E2:E100). Use F4 to toggle absolute references if needed.
- Combine with AGGREGATE: For more robust error handling, use AGGREGATE (e.g.,
=AGGREGATE(9,5,D2:D100)), where 5 ignores hidden rows and error values. Function 9 and 5 work similarly to SUBTOTAL(9) for visible-only sums. - Check filtered state first: Before trusting the total, confirm your filter is active (little funnel icon in the header) and rows are genuinely hidden—not just scrolled out of view.
- Use the Subtotal tool for automatic grouping: For multi-level subtotals, go to Data > Subtotal, but note this inserts grand totals and is less flexible than manual SUBTOTAL formulas.
- Test with extreme filters: Filter to show only 1 row or hide all rows—SUBTOTAL returns 0 when no rows match, which is correct behavior.
Troubleshooting
If your SUBTOTAL doesn’t update when filtering:
- Check for manual hiding: Right-click any row > Unhide to reveal all. If the subtotal changes after unhiding, your SUBTOTAL(9) was already ignoring hidden rows—but ensure you’re using filters (not manual hide) to test it.
- Verify the formula syntax: Open the formula bar and confirm it reads
=SUBTOTAL(9,range)with no extra spaces, typos, or quotes (e.g., no"9"as text). - Check for non-numeric data: If the target column contains text (e.g., "N/A" or blanks treated as text), SUBTOTAL(9) ignores them, but if errors like #N/A exist, wrap it in IFERROR:
=IFERROR(SUBTOTAL(9,D2:D100),0). - Recalculate manually: Press F9 to force full recalculation. If it still doesn’t update, go to Formulas > Calculation Options > Automatic.
- Inspect row visibility: In filtered data, hidden rows show a thin line between visible rows. If no rows appear hidden but the subtotal is wrong, reapply the filter: Data > Clear > Clear Filters from [Sheet Name].
- Ensure no merged cells: Merged cells in the data range can disrupt SUBTOTAL. Unmerge them (Home > Merge & Center > Unmerge Cells).
Frequently Asked Questions
Does SUBTOTAL work with Excel for the web?
Yes—the SUBTOTAL function is fully supported in Excel for the web, including filtering and real-time updates when you change filter criteria in the browser.Can I subtotal multiple columns at once with one formula?
No. SUBTOTAL processes one range per formula. To subtotal several columns (e.g., Sales and Quantity), enter separate SUBTOTAL formulas for each column (e.g.,=SUBTOTAL(9,D2:D100) and =SUBTOTAL(9,E2:E100)).
Why does my subtotal show 0 even with visible data?
Check if the numeric column contains text-formatted numbers (green triangles in cells). Convert them to numbers via Data > Text to Columns, or use=SUBTOTAL(9,--D2:D100) to force conversion (array-enter with Ctrl+Shift+Enter in older Excel versions).