Combining SUBTOTAL and COUNTIF lets you count rows that meet a condition while respecting filters and hidden rows, so the number on screen always matches what you can see. The usual way is =SUBTOTAL(103, helper_range) where the helper column holds a COUNTIF result: =COUNTIF(criteria_range, "condition"). SUBTOTAL with function number 103 counts only visible, non-blank cells; when a row is filtered out or hidden, its value drops from the total. That is exactly what a plain COUNTIF cannot do, because COUNTIF ignores filters and counts every matching row in the range whether you can see it or not. You need Excel 2010 or later (SUBTOTAL has been there far longer, but the 1xx function numbers that skip hidden rows are essential here). Steps below are written for the desktop version of Excel on Windows and Mac; the browser and mobile versions support the same functions, though the filter menus look different. Menu and ribbon labels can differ slightly by version, device or region.
What You'll Need
- A table or range of data with at least one column of values you want to test (status, region, category, and so on).
- A column you can use as a helper, or willingness to add one. You can work without a helper column, but it is more fragile.
- AutoFilter switched on for the data (Data > Filter, or Ctrl+Shift+L on Windows, Cmd+Shift+L on Mac).
- An empty cell area for your summary formula, ideally outside the filtered range.
Step-by-Step
- Set up the filter. Select the whole data range including headers and turn on Data > Filter. Confirm every header shows a drop-down arrow in the first row.
- Add a helper column. In the first blank column beside the data, give the header a name such as Match. In the first data row (say row 2) enter
=COUNTIF($C$2:$C$500, "Open")whereCis the status column and"Open"is the value you want to count. This returns 1 when the row matches and 0 when it does not. - Widen the COUNTIF range deliberately. Use an absolute range ($C$2:$C$500) so copying the formula down does not shift the rows being tested. Alternatively, point the COUNTIF at the single cell in the same row,
=COUNTIF($C2, "Open"), which is easier to copy, but only if one cell can hold the whole test. - Fill the helper formula down to the last data row by dragging the fill handle or double-clicking it. Every row should now show 1 or 0.
- Write the SUBTOTAL wrapper. In your summary cell type
=SUBTOTAL(103, $E$2:$E$500)whereEis the helper column. The 103 means COUNTA that ignores hidden rows: it counts visible helper cells containing a number, and because every visible row holds either 1 or 0, the result is the number of visible matching rows. - Test it. Filter the status column to Open. The SUBTOTAL result should now equal the number of visible Open rows. Filter to a different value and watch the number change.
- Confirm the difference. Next to it, put a plain
=COUNTIF($C$2:$C$500, "Open"). This stays fixed at the full dataset total, which shows exactly why the SUBTOTAL wrapper matters. - Make it dynamic if you like. Replace the literal
"Open"with a cell reference such as$H$1so the count follows whatever you type in that cell. Use=SUBTOTAL(103, $E$2:$E$500)unchanged. - Replace the helper with SUBTOTAL arithmetic only when needed. If you need a count of visible rows matching a condition without a helper column, you can use
=SUMPRODUCT((C2:C500="Open")*(SUBTOTAL(103, OFFSET(C2:C500, ROW(C2:C500)-MIN(ROW(C2:C500)),0,1)))), but it is slower on large ranges and harder to audit. The helper-column method is safer for everyday work. - Lock the result cell. If the summary formula sits inside the data range it will be filtered too. Keep summaries in a separate area or in a frozen top row, and freeze panes with View > Freeze Panes so the number stays visible while you scroll.
Common Mistakes
Using 3 instead of 103. Function number 3 is COUNTA that includes hidden and filtered rows, so the total never changes. Always use 101–111 when you want filter-aware results; the 100-series skips manually hidden rows as well as filtered ones.
Counting the wrong thing. SUBTOTAL(103) counts non-empty cells, not the sum of their values. If the helper returns 1 or 0, you get the count of visible rows, which is what you want. If the helper contains the text "Match" instead of a number, COUNTA still counts it, but SUM (109) would return 0. Pick the function to match the data type.
Leaving the COUNTIF range relative. A range like C2:C500 copied down becomes C3:C501, C4:C502, and the last rows silently lose rows off the bottom. Anchor the range with dollar signs.
Forgetting that hidden rows differ from filtered rows. SUBTOTAL with 103 skips both, which is usually desirable, but if you hide rows for layout reasons and expect them counted, use 3 instead.
Wrapping COUNTIF outside SUBTOTAL. =COUNTIF(SUBTOTAL(...)) is not valid in that order and does not do what people expect. The SUBTOTAL must be the outer function wrapping the helper values.
Tips
Convert the range to an Excel Table (Insert > Table) first: structured references such as Table1[Status] expand automatically as rows are added, so you never edit ranges again. Note that SUBTOTAL inside a Table's total row already ignores filtered rows, which can save a step.
Use a drop-down in a spare cell (Data > Data Validation > List) to switch criteria without editing formulas. Combine two conditions by multiplying two COUNTIF tests in the helper: =COUNTIF(C2,"Open")*COUNTIF(D2,"North") returns 1 only when both match. For a percentage of visible rows, divide SUBTOTAL(103, E2:E500) by SUBTOTAL(103, A2:A500) using an always-populated column such as an ID, and format the result as a percentage.
Troubleshooting
The total does not change when you filter. Check the first argument: 3 instead of 103 is the usual cause. Also confirm the filter is a real AutoFilter, not rows hidden manually and not a filter applied to a different range.
The result is higher than expected. Your helper range probably extends beyond the data and contains stray spaces, formulas returning empty strings, or notes below the table. Select the range and press Ctrl+End (Cmd+End on Mac) to find the true last used cell, then trim the range.
The result is zero. The criteria text does not match exactly. COUNTIF is not case-sensitive, but it is space-sensitive and wildcard-sensitive: an asterisk or question mark in the criteria is treated as a wildcard. Check for leading or trailing spaces in the source data and test the bare COUNTIF first to see whether it returns anything.
#VALUE! errors. Usually a helper cell contains an error that SUBTOTAL propagates. Trace it with Formulas > Evaluate Formula or filter the helper column for errors.
Nothing works after a copy-paste. Pasting the summary formula into a filtered sheet can land it in a hidden row. Paste while the filter is cleared, or paste into a cell above the filtered range.
Frequently Asked Questions
Can I use COUNTIF inside SUBTOTAL directly?
No. SUBTOTAL expects a range of values, not a function. Put COUNTIF in a helper column and wrap SUBTOTAL around that column, or use the SUMPRODUCT/OFFSET construction described above.
What is the difference between SUBTOTAL 3 and 103?
3 counts all non-empty cells including hidden and filtered rows; 103 counts only visible ones. Use 103 for filter-aware counts.
Does SUBTOTAL work with COUNTIFS-style multiple criteria?
Not in one argument. Use COUNTIFS in the helper column instead of COUNTIF and keep the SUBTOTAL wrapper the same.
Why does my SUBTOTAL ignore rows I hid manually?
That is intentional for the 100-series function numbers. If you want manually hidden rows included but filtered rows excluded, there is no single SUBTOTAL number for that; you would need a helper that tests row height, which is more advanced.
Will this work in Excel for the web or on a phone?
Yes, SUBTOTAL and COUNTIF are supported in Excel for the web and the mobile apps. Filtering works too, though the filter interface differs; the formulas behave the same.