The SUBTOTAL function in Excel lets you count visible rows in a filtered list while ignoring hidden rows, making it ideal for dynamic data analysis. Unlike COUNT or COUNTA, SUBTOTAL adapts when you apply filters, so you only count what’s visible. You need Excel 2010 or later and a data range with headers to use it effectively.
What You'll Need
- Microsoft Excel 2010 or newer (Windows or Mac)
- A table or range of data with column headers
- At least one filtered column to test the functionality
Step-by-Step
- Ensure your data is formatted as a table or has consistent headers. Select your data range and press Ctrl+T (or Cmd+T on Mac) to convert it into an Excel Table if it isn’t already. This helps Excel recognize structured data, though it’s not required for SUBTOTAL to work.
- Click anywhere inside your data range. Go to the Data tab on the ribbon and click Filter. This adds dropdown arrows to each column header.
- Click the dropdown arrow in any column you want to filter. Uncheck "Select All" and then check only a few items to hide most rows. For example, if you’re filtering a Sales column, check only "North" to hide other regions.
- Click an empty cell below your data or in a separate summary section. This is where the SUBTOTAL result will appear.
- Type the formula: =SUBTOTAL(102, range), replacing "range" with the actual cell range of the column you want to count. For example, if your sales data is in column B from row 2 to row 100, type =SUBTOTAL(102, B2:B100). The number 102 tells Excel to count numeric values in visible rows only.
- Press Enter. The result will show only the count of visible rows in that column, ignoring any hidden by the filter.
- To count text entries instead of numbers, use 103 instead of 102. For example, =SUBTOTAL(103, A2:A100) counts visible cells containing text or numbers in column A.
- Test the function: change your filter to show more or fewer rows. Notice how the SUBTOTAL result updates automatically — this confirms it’s working correctly.
Common Mistakes
- Using COUNT or COUNTA instead of SUBTOTAL — these functions count all rows, even hidden ones, defeating the purpose of filtering.
- Using function number 2 or 3 instead of 102 or 103 — numbers 2 and 3 count hidden rows too. Always use 102 for visible numeric counts and 103 for visible text/number counts.
- Referencing the entire column (e.g., B:B) — while technically allowed, this can slow down large spreadsheets. Always use a specific range like B2:B1000.
- Forgetting to apply a filter — SUBTOTAL only shows its dynamic behavior when rows are actually hidden by filtering. If no rows are hidden, it behaves like COUNTA, which may cause confusion.
- Putting the SUBTOTAL formula inside the filtered range — this can cause circular references or incorrect totals. Always place the formula below or outside the data range.
Tips
- Use SUBTOTAL with multiple columns: You can add separate SUBTOTAL formulas for different columns to get counts for each category independently.
- Combine with PivotTables: If you frequently filter and summarize data, consider using a PivotTable instead — it handles dynamic counts natively and supports more complex groupings.
- Use named ranges: If your data range is large or changes often, define a named range (Formulas > Define Name) and use that name in your SUBTOTAL formula for easier maintenance.
- Check for merged cells: SUBTOTAL works best with clean, unmerged data. Merged cells can cause unexpected behavior in filters and formulas.
- Use 109 for summing visible values: If you also need to sum visible numeric data, use 109 instead of 102. For example, =SUBTOTAL(109, C2:C100) sums only visible values in column C.
- Remember the difference between 102 and 103: 102 counts only cells with numbers (ignoring blank or text cells), while 103 counts any non-empty cell (text, numbers, errors). Choose based on your data type.
Troubleshooting
- If the result doesn’t change when you filter: Check that you’re using 102 or 103, not 2 or 3. Also confirm the filter is actually hiding rows — click the dropdown and check the box next to "(Blanks)" or other items to ensure rows are being hidden.
- If you get a #REF! error: Your range reference is invalid. Double-check that the cells in your range exist and aren’t deleted. If you moved or deleted data, update the range in the formula.
- If the formula returns 0 but you see visible data: You might be using 102 on a column that contains only text. Switch to 103. Or, your data may be stored as text formatted as numbers — select the column, click Data > Text to Columns > Finish to convert it.
- If Excel slows down: Avoid entire-column references like A:A. Use a fixed range like A2:A5000. Also, avoid placing SUBTOTAL in every row — use it only in summary cells.
- If SUBTOTAL doesn’t work with manual row hiding: SUBTOTAL only ignores rows hidden by filters, not rows manually hidden by right-clicking and choosing Hide. To hide rows and have SUBTOTAL ignore them, use a filter instead.