The SUBTOTAL function with function number 3 is used to count the number of non-empty cells in a range while ignoring rows that have been hidden by a filter. Unlike the standard COUNTA function, which counts every cell regardless of whether it is visible, SUBTOTAL(3, range) dynamically updates its result to reflect only the data currently displayed on your screen after a filter is applied. This makes it the primary tool for creating dynamic dashboards and summary reports where the count needs to change based on user selection.

What You'll Need

  • Microsoft Excel (any modern version including Excel 365, 2021, 2019, or Excel for the Web).
  • A dataset containing at least one column of data (text, numbers, or a mix) that you intend to filter.
  • A basic understanding of how to apply filters to a data range.

Step-by-Step

  1. Prepare Your Data: Ensure your data is organized in a tabular format with clear headers at the top of each column. For example, if you have a list of sales leads, your headers might be "Lead Name," "Region," and "Status." Ensure there are no completely empty rows within your data block, as this can interfere with how Excel recognizes the range.
  2. Apply a Filter to Your Headers: Select any cell within your data range. Navigate to the Data tab on the top ribbon and click the Filter button. You will now see drop-down arrows appearing in the header cell of every column.
  3. Position Your Subtotal Formula: It is highly recommended to place your SUBTOTAL formula above your data headers rather than below them. If you place the formula at the bottom, it may be hidden when you filter the list, or you may accidentally include the formula cell itself in the range, creating a circular reference error. Click on a cell in row 1 or 2, above your dataset.
  4. Enter the Formula: Type the following formula into the cell: =SUBTOTAL(3, B5:B100). In this example, 3 is the function number telling Excel to perform a COUNTA (count non-empty cells), and B5:B100 is the range of cells you want to count. Replace B5:B100 with the actual range of your data column.
  5. Press Enter: Once you press Enter, the cell will display the total count of all non-empty cells in that range. At this stage, since no filters are applied, the number will be identical to what a standard =COUNTA() formula would return.
  6. Test the Filter: Click the drop-down arrow in one of your header columns (e.g., the "Region" column). Uncheck "Select All" and select only one specific region, such as "North." Click OK.
  7. Observe the Dynamic Update: Look at the cell containing your SUBTOTAL formula. You will notice that the number has automatically decreased. It is no longer counting the entire list; it is now only counting the rows that are currently visible.
  8. Clear Filters to Reset: To return to the full count, go back to the Data tab and click Clear (next to the Filter button), or use the drop-down menu in the column header and select "Clear Filter From..." The SUBTOTAL result will instantly jump back to the original total.

Common Mistakes

One of the most frequent errors is using the wrong function number. Users often confuse SUBTOTAL(3, ...) with SUBTOTAL(103, ...). While both count non-empty cells, function 3 ignores rows hidden by a filter, whereas function 103 ignores rows hidden by a filter and rows that have been manually hidden by right-clicking the row header and selecting "Hide." If you are only using the Filter tool, 3 is sufficient, but if you manually hide rows, 3 will still count them, leading to an inflated total.

Another common mistake is including the formula cell within the range of the formula itself. For instance, if your formula is in cell B1 and you set the range as B1:B100, Excel will trigger a circular reference warning. This happens because the formula is trying to count the cell that contains the formula. Always ensure your range starts below the row where the formula resides.

Users also frequently apply the SUBTOTAL function to a column that contains empty cells within the data set. Because function 3 is based on COUNTA, it only counts cells that have content. If your data has gaps (empty cells), the SUBTOTAL result will not represent the total number of rows, but rather the total number of populated cells. To avoid this, always point the formula to a "Primary Key" column—a column like an ID number or Name that is guaranteed to be filled for every single record.

Tips

To make your spreadsheet more professional and easier to maintain, convert your data range into an official Excel Table. Select your data and press Ctrl + T. When you use a Table, you can enable a "Total Row" by going to the Table Design tab and checking the Total Row box. Excel will automatically add a row at the bottom with a drop-down menu that allows you to select "Count." This automatically uses the SUBTOTAL function behind the scenes, and the range adjusts automatically as you add or remove rows, meaning you never have to manually update the cell references (e.g., changing B100 to B200).

If you need to count multiple different criteria across a filtered list, you cannot use the standard COUNTIFS function because COUNTIFS does not ignore hidden rows. Instead, you can create a "helper column." In the helper column, use the formula =SUBTOTAL(3, A2) for every row. This will return a 1 if the row is visible and a 0 if it is hidden. You can then use a SUMIF formula based on that helper column to perform more complex conditional counts on filtered data.

For those working with very large datasets, avoid using too many SUBTOTAL functions across thousands of rows, as these are volatile functions. A volatile function recalculates every time any change is made to the worksheet, which can lead to lag in extremely large workbooks. Place your summaries in a dedicated header area to keep the calculation load manageable.

Troubleshooting

If your SUBTOTAL(3, ...) formula is returning the same number regardless of whether you filter the data or not, the most likely cause is that you are not using a proper filter. Ensure that you have used the Data > Filter tool. If you have simply colored rows or moved them around, the SUBTOTAL function will not recognize them as "hidden." The rows must be hidden specifically by the Excel Filter mechanism or the Hide Row command (if using function 103).

If the formula returns a #VALUE! error, check your range references. This usually happens if the range refers to a different workbook that is currently closed or if the range is invalid. Ensure that the range is within the same sheet or that the external reference is correctly linked.

If the count seems lower than expected, check for trailing spaces or truly empty cells in your target column. Since function 3 counts non-empty cells, any cell that is completely blank will be ignored. If a cell looks empty but is actually counted, it likely contains a space character or a formula that returns an empty string (""). Excel treats a formula-generated empty string as a non-empty cell, which can skew your count.

Frequently Asked Questions

What is the difference between SUBTOTAL 3 and COUNTA?

COUNTA counts all non-empty cells in a range, regardless of whether they are visible or hidden. SUBTOTAL 3 only counts non-empty cells that are currently visible after a filter has been applied.

Does SUBTOTAL 3 count blank cells?

No, SUBTOTAL 3 is based on the COUNTA function, which specifically ignores empty cells. It only counts cells that contain text, numbers, errors, or formulas.

Why use 103 instead of 3?

Use 3 if you only care about rows hidden by the AutoFilter tool. Use 103 if you want to ignore rows that were manually hidden (by right-clicking the row and selecting Hide) in addition to those hidden by a filter.

Can I use SUBTOTAL 3 for a sum instead of a count?

No, the number 3 specifically tells Excel to perform a count. If you want to sum the visible values in a range, you should use function number 9 (or 109 for manually hidden rows), as in =SUBTOTAL(9, range).

Will SUBTOTAL 3 work in Excel for the Web?

Yes, the SUBTOTAL function is fully supported in Excel for the Web and behaves the same way as it does in the desktop application.

Can SUBTOTAL 3 count unique values?

No, SUBTOTAL 3 counts all non-empty cells. To count unique values in a filtered list, you would need a more complex formula combining SUMPRODUCT, SUBTOTAL, and COUNTIF, or use a Pivot Table.