To count cells using the SUBTOTAL formula in Excel, use the syntax =SUBTOTAL(function_num, ref1), where the function number determines whether you are counting numbers or non-empty cells and whether you want to include or ignore manually hidden rows. Unlike the standard COUNT or COUNTA functions, SUBTOTAL is dynamic; it updates its result automatically when you apply a filter to your data range, allowing you to see the count of only the visible rows currently displayed on your screen.

What You'll Need

  • A dataset in Microsoft Excel (Desktop, Web, or Mac versions).
  • A column of data that you intend to count (numeric values or text).
  • The data should ideally be formatted as an Excel Table (Ctrl + T) for the best experience, though it works on standard ranges as well.

Step-by-Step

  1. Prepare your data range: Ensure your data is organized in columns with clear headers. For example, if you are counting employees, ensure you have a column labeled "Employee Name" or "ID Number."
  2. Identify your counting goal: Decide if you want to count only cells containing numbers (use function 2 or 102) or all cells that are not empty, such as text names (use function 3 or 103).
  3. Select the destination cell: Click on the empty cell where you want the subtotal result to appear. This is usually located directly above or below your data set to avoid being hidden when filters are applied.
  4. Enter the formula: Type the equals sign = followed by SUBTOTAL(.
  5. Input the function number: This is the most critical part. You must type a number that tells Excel what to do.
    • Use 3 to count all non-empty cells (equivalent to COUNTA) including manually hidden rows.
    • Use 103 to count all non-empty cells (equivalent to COUNTA) but exclude rows that you have manually hidden via right-click > Hide.
    • Use 2 to count only cells containing numbers (equivalent to COUNT) including manually hidden rows.
    • Use 102 to count only cells containing numbers (equivalent to COUNT) but exclude manually hidden rows.
  6. Define the range: Type a comma , then select the range of cells you want to count with your mouse, or type the range manually (e.g., A2:A50).
  7. Close and execute: Type a closing parenthesis ) and press Enter. Your formula should look like this: =SUBTOTAL(103, A2:A50).
  8. Test the filter: Go to the Data tab and click Filter. Use the dropdown arrows in your column headers to filter out certain values. Notice how the result of your SUBTOTAL formula changes to reflect only the number of visible rows.

Common Mistakes

One of the most frequent errors is choosing the wrong function number. Users often use 3 when they actually need 103. While both will respond to active filters applied via the Filter dropdown menu, function 3 will still include rows that you have manually hidden by right-clicking a row number and selecting "Hide." If your goal is to see a count of only what is physically visible on the screen regardless of how it was hidden, always opt for the 100-series numbers (102, 103, etc.).

Another mistake is attempting to use SUBTOTAL on a range that includes the formula cell itself. This creates a circular reference error, where Excel tries to calculate a total that includes the total, leading to an error or a zero result. Always place your subtotal formula in a separate row, ideally at the very top of your sheet or in a dedicated summary area above the headers.

Users also frequently confuse SUBTOTAL with AGGREGATE. While they are similar, SUBTOTAL has a limited set of functions and cannot ignore error values within a range. If your data contains #N/A or #DIV/0! errors, a SUBTOTAL formula might return an error instead of a count. In those specific cases, the AGGREGATE function is a more robust alternative.

Tips

For maximum efficiency, convert your data range into an official Excel Table by selecting the range and pressing Ctrl + T. When you use a Table, you can use structured references in your formula, such as =SUBTOTAL(103, Table1[Employee Name]). This is much more reliable because as you add new rows to the bottom of the table, the formula automatically expands to include them. You will never have to manually update the range A2:A50 to A2:A51.

If you are working with very large datasets, place your SUBTOTAL formula in the top rows (Rows 1 or 2) and freeze those rows. To do this, go to the View tab, select Freeze Panes, and then Freeze Top Row. This ensures that as you scroll down through thousands of rows of data, your dynamic count remains visible at the top of your screen at all times.

Troubleshooting

If your formula is returning 0 when you know there is data, check if your data is actually formatted as text or numbers. If you are using function 102 (which counts numbers) on a column of numbers that Excel has stored as "Text," the result will be 0. You can fix this by selecting the column, clicking the warning icon that appears, and selecting "Convert to Number."

If the formula does not change when you apply a filter, ensure you are actually using the SUBTOTAL function and not the standard COUNT or COUNTA functions. Standard functions are "blind" to filters; they will always return the total count of the entire range, regardless of what is hidden. Check your formula bar to confirm it starts with =SUBTOTAL.

If you see a #VALUE! error, it usually means there is a syntax error in your formula, such as a missing comma between the function number and the range, or a typo in the range reference. Re-type the formula from scratch if the error persists, ensuring you follow the (number, range) pattern strictly.

Frequently Asked Questions

What is the difference between function 3 and 103?

Function 3 counts non-empty cells but includes rows that you have manually hidden. Function 103 counts non-empty cells and excludes both filtered-out rows and manually hidden rows.

Can SUBTOTAL count text?

Yes, if you use function 3 or 103. These are the equivalent of the COUNTA function, which counts any cell that is not empty, whether it contains text, numbers, or dates.

Why does my SUBTOTAL return an error when my data has errors in it?

The SUBTOTAL function is not designed to ignore error values like #REF! or #VALUE! within the range. If your range contains errors, the subtotal will also return an error. Use the AGGREGATE function instead to ignore errors.

Does SUBTOTAL work in Excel for Web?

Yes, the SUBTOTAL function is fully supported in Excel for the Web and functions identically to the desktop version, allowing you to count filtered rows in your browser.

How do I count only visible numbers?

Use the function number 102. The 100-series ensures that manually hidden rows are ignored, and the '2' tells Excel to only count cells containing numeric values.

Can I use SUBTOTAL in a Pivot Table?

Pivot Tables have their own built-in subtotaling logic. While you can use SUBTOTAL formulas alongside a Pivot Table, they are separate entities. The Pivot Table will manage its own subtotals based on the fields you drag into the Rows and Values areas.