You can count non-empty cells in a range using the SUBTOTAL function with the number 102 for the COUNTA argument. This counts text, numbers, and logical values but ignores hidden rows. To use it, type =SUBTOTAL(102, range) into a cell, replacing range with your specific cell references.

What You'll Need

  • A computer with Microsoft Excel installed (Excel 2010 or later is recommended for the best feature compatibility, though the formula works in older versions).
  • A dataset containing the data you wish to count. This data can be a simple column, a block of cells, or a named range defined within your workbook.
  • A basic understanding of cell references (absolute vs. relative) is helpful, though not strictly required.

Step-by-Step

  1. Open your workbook. Launch Microsoft Excel and open the spreadsheet that contains the data you want to analyze. Ensure the data is organized in a way that allows you to easily select the specific cells you intend to count. For this guide, imagine you have a list of sales transactions in column A, spanning from A2 to A100.
  2. Select the cell where you want the result. Click on any empty cell in your sheet where you would like the total count to appear. This cell will serve as the output display for your formula. It is best to place this to the right or below your data range for easy viewing.
  3. Begin typing the formula. Type an equals sign (=) to start a new formula. Immediately following the equals sign, type the word SUBTOTAL. Excel will likely display a tooltip or auto-complete suggestion to confirm you are on the right track.
  4. Enter the function number. After the opening parenthesis, you must provide the first argument: the function number. For COUNTA, which counts all values that are not empty, you use the number 102. Type 102 followed by a comma.
  5. Specify the range. Next, indicate which cells to count. You can either type the cell references manually (e.g., A2:A100) or click and drag your mouse to highlight the desired range directly on the spreadsheet. Once your range is selected, release the mouse button. If you typed the references manually, close the parenthesis to finish the formula.
  6. Press Enter. Press the Enter key on your keyboard to finalize the formula. Excel will calculate the count of non-empty cells within your specified range and display the result in the cell where you typed the formula.
  7. Verify the result. Double-check the result to ensure it matches your expectations. If you have hidden rows within your selection, SUBTOTAL(102, ...) will correctly exclude them from the count, whereas a standard COUNTA formula would include them.

Common Mistakes

One of the most frequent errors users make is using the wrong function number. Excel offers different function numbers for different operations within the SUBTOTAL family. While 102 is the correct code for COUNTA, confusing it with 1 (which is AVERAGE) or 2 (which is COUNT, counting only numbers) will result in a completely incorrect calculation.

Another common issue arises when the range selected is too broad or too narrow. If you select an entire column (e.g., A:A), the formula will attempt to count every single cell in that column, which may include empty header cells or data far outside your actual dataset. Selecting a specific range of cells (e.g., A2:A100) is much safer and more accurate.

Tips

For large datasets, consider using Excel Tables (formerly known as Lists). By converting your data into a Table (Insert > Table), you can use structured references. This makes your formula easier to read and maintain. If you add new data to the bottom of the table, the SUBTOTAL formula will automatically expand to include the new rows without you needing to edit the range.

Always remember the distinction between the two sets of function codes in SUBTOTAL. Codes 1 through 11 include hidden values, while codes 101 through 111 ignore them. If you are using filters or hiding rows to analyze subsets of your data, you must use the 100 series (e.g., 102) to ensure your count reflects only the visible data.

Troubleshooting

If the formula returns a value of zero, the first thing to check is whether the range actually contains any non-empty cells. It is possible that the data is formatted as text or contains spaces, which COUNTA does count, but if the cells are truly empty, the result will be zero.

If the result is incorrect because you are seeing hidden rows in the count, you likely used the wrong function code. Ensure you are using 102, not a code in the 1–11 range. If you intended to count hidden rows and are seeing the wrong number, check that you are using the lower numbers (1–11) instead.

If the formula does not update when you change the data, check if Automatic Calculation is enabled. Go to the Formulas tab on the ribbon and ensure the Calculation Options dropdown is set to Automatic. If it is set to Manual, you will need to press F9 to update the formula.

Frequently Asked Questions

Does SUBTOTAL(102, ... ) work with filtered data?

Yes, it does. When you apply an auto-filter to your data and hide rows, SUBTOTAL with function number 102 will only count the visible, non-empty cells. This is different from the standard COUNTA function, which counts all cells regardless of their visibility.

What is the difference between COUNT and COUNTA?

The COUNT function (function number 2 or 100) only counts cells that contain numeric values. The COUNTA function (function number 102) counts all cells that are not empty, including text, logical values, and errors, in addition to numbers.

Why is my SUBTOTAL formula showing a #VALUE! error?

This error usually occurs if the range argument contains text that cannot be interpreted as a number, or if there is a formatting issue with the cells. However, since COUNTA is designed to count text, this is rare. If you see this error, double-check that you didn't accidentally include a cell that contains an error value (like #DIV/0!) in your range, as COUNTA does count error values.

Can I use SUBTOTAL(102, ...) across different worksheets?

No, the SUBTOTAL function cannot directly reference cells on a different worksheet. You must combine the results of individual SUBTOTAL formulas from each sheet into a single cell using a standard SUM formula (e.g., =SUM(SUBTOTAL(102,Sheet2!A2:A100), SUBTOTAL(102,Sheet3!A2:A100))).

Does SUBTOTAL(102, ...) count cells with formulas that return empty strings?

Yes. If a cell contains a formula that results in an empty string (=""), COUNTA and SUBTOTAL(102) will treat that cell as non-empty because the formula has produced a value, even if that value is invisible to the eye.