The SUBTOTAL function with code 103 in Excel counts only visible cells in a filtered list or table, ignoring rows hidden by a filter or manually. It is the standard way to get an accurate count of what you actually see on screen, and it updates automatically when you change filters. You do not need any special setup—just a worksheet with data and a place to put the formula.
What You'll Need
- A worksheet with data in rows and columns (e.g., a list of sales, inventory, or names).
- Excel 2010 or later (the function works the same in Excel for Microsoft 365, Excel 2021, 2019, 2016, and older versions).
- Basic familiarity with entering formulas in a cell.
Step-by-Step
- Identify the range you want to count. For example, if you have a list of orders in cells A2:A100, that is your range. The formula will count the number of cells in that range that contain numbers, but only those that are visible after filtering.
- Click an empty cell where you want the count to appear. This is often placed above or below the data, or on a summary row.
- Type the formula:
=SUBTOTAL(103, A2:A100). ReplaceA2:A100with your actual range. The number103is the function code for COUNTA (count non-empty cells) that ignores hidden rows. If you want to count only numeric values (not text), use code102instead, which is COUNT. For most lists, 103 is what you want because it counts text and numbers. - Press Enter. The cell will show the total count of visible non-empty cells in that range.
- Test it with a filter. Select your data, go to the Data tab, and click the Filter button (or press Ctrl+Shift+L). Click the drop-down arrow in a column header, uncheck some items, and click OK. The SUBTOTAL formula will update automatically to show only the visible rows.
- If you manually hide rows (right-click a row number and choose Hide), the formula also ignores those. That is the difference between 103 and 101 (which ignores only filtered rows, not manually hidden ones).
- Use it with Excel Tables. If your data is in a formatted Excel Table (Insert > Table), you can use a structured reference like
=SUBTOTAL(103, Table1[Column1]). This automatically adjusts as you add or remove rows.
The formula is dynamic: it recalculates every time you change a filter or hide/unhide rows. You do not need to press F9 or re-enter it.
Common Mistakes
- Using 9 instead of 103. Code 9 is the old COUNTA that counts all rows, including hidden ones. If you use 9, the count will not change when you filter. Always use 103 for visible-only counting.
- Including the header row in the range. If your data starts in row 2 and row 1 is a header, do not include row 1 in the range.
=SUBTOTAL(103, A1:A100)would count the header if it is non-empty, giving you one extra. - Using the formula in a row that is itself hidden. If you put the formula in a row that gets hidden by a filter, the result may be hidden too. Place it outside the filtered area, such as in a row above the header or in a separate summary section.
- Counting blank cells. SUBTOTAL with 103 counts non-empty cells. If your range has blank cells, they are not counted. If you need to count all visible rows regardless of content, you would need a different approach (like counting row numbers).
- Forgetting to refresh after changing data. Normally Excel recalculates automatically, but if you have manual calculation mode (Formulas > Calculation Options > Manual), you need to press F9 to update.
Tips
- Use SUBTOTAL for all summary rows. If you have a total row in a filtered list, use SUBTOTAL with code 109 for SUM (visible sum) or 103 for count. This keeps your summary accurate when filters change.
- Combine with AGGREGATE for more power. The AGGREGATE function (e.g.,
=AGGREGATE(2,5,A2:A100)) also counts visible cells and can ignore errors. But SUBTOTAL is simpler and works in Excel Tables. - Create a dynamic count for a dashboard. Place a SUBTOTAL formula in a cell, then use that cell in charts or other formulas. It will always reflect the current filter state.
- Use 103 for text and numbers, 102 for numbers only. If your column contains mixed data, 103 is safer. If you only have numbers, 102 is fine but 103 also works.
- Keyboard shortcut for AutoFilter: Ctrl+Shift+L toggles filters on and off. This is handy when testing your formula.
Troubleshooting
The count does not change when I filter. Check that you used 103, not 9. Also make sure the formula range covers the entire data area. If you have an Excel Table, ensure the range includes all rows, not just a few.
The count is off by one or more. Check if your range includes a header or blank rows. Adjust the range to start at the first data row and end at the last possible row. Also check for merged cells—they can cause issues with counting.
The formula returns 0 even though there are visible rows. This happens if the range contains only blank cells or if the cells contain formulas that return empty text (""). SUBTOTAL 103 counts cells that are not blank, but empty text from a formula is considered blank for COUNTA? Actually, COUNTA counts cells that contain any value, including empty text. But if your cells are truly empty, the count is 0. Check that your data is in the correct column and that the range is correct.
The formula shows #VALUE! error. This usually means the range is invalid. Check for typos, or if you used a structured reference, make sure the table name and column name are correct. Also ensure there are no extra spaces in the formula.
When I manually hide rows, the count does not update. That is expected if you used 101 instead of 103. Code 101 ignores only filtered rows, not manually hidden ones. Use 103 to ignore both.
Frequently Asked Questions
What is the difference between SUBTOTAL(103) and SUBTOTAL(3)?
SUBTOTAL(3) is the old COUNTA that counts all non-empty cells, including hidden ones. SUBTOTAL(103) is the same function but with the option to ignore hidden rows. Use 103 for filtered data.
Can I use SUBTOTAL 103 in a pivot table?
Pivot tables have their own way of counting (usually COUNT or COUNTA). You do not need SUBTOTAL inside a pivot table. But you can use SUBTOTAL in a cell outside the pivot table to count visible rows of a filtered list.
Does SUBTOTAL 103 work with Excel Tables?
Yes. In fact, when you add a Total Row to an Excel Table, the dropdown lets you choose "Count" which uses SUBTOTAL(103) automatically. You can also write the formula manually with structured references.
How do I count visible rows that are blank?
SUBTOTAL 103 counts only non-empty cells. To count all visible rows including blanks, you would need a more complex array formula or a helper column. A simpler way is to use a formula like =SUMPRODUCT(SUBTOTAL(3,OFFSET(A2,ROW(A2:A100)-ROW(A2),0))) but that is advanced. For most purposes, 103 is sufficient.
Why does my SUBTOTAL formula show a different number than the status bar count?
The status bar shows "Count" which is the number of numeric cells, not text. If your data is text, the status bar may show "Count" as 0. SUBTOTAL 103 counts non-empty cells, so it will be higher. Use 102 if you want to match the numeric count.
Can I use SUBTOTAL 103 with multiple ranges?
SUBTOTAL accepts only one range per function. If you need to count across multiple non-contiguous ranges, you must use multiple SUBTOTAL functions and add them, or use a different function like AGGREGATE. For example: =SUBTOTAL(103, A2:A10) + SUBTOTAL(103, C2:C10).