The goal is to count the number of cells in a given range, regardless of whether the cells are empty or not. Although Excel has several functions designed to count cells based on their contents, there is no built-in function for counting the total number of cells in a range. The classic solution is to use a formula based on the ROWS function and the COLUMNS function. It is also possible to force the COUNTA function to count all cells, empty or not. Both approaches are explained below.
ROWS + COLUMNS
This is the approach used in the worksheet shown, where the formula in cell J5 is:
The ROWS function returns the count of rows in a range. Since there are 12 rows in the range B4:H16, ROWS returns 12. In the same way, The COLUMNS function returns the count of columns in a range, which is 7 in this case. The formula is evaluated by Excel like this:
=ROWS(B4:H16)*COLUMNS(B4:H16) =12*7 =91
Count all cells in a worksheet
The ROWS and COLUMNS functions can work with any sized rectangular range. For example, the formula below uses the ROWS function to count all rows in column A, and the COLUMNS function to count all columns in row 1:
=ROWS(A:A)*COLUMNS(1:1) // count all cells in worksheet
ROWS returns a count of 1,048,576 and COLUMNS returns a count of 16,384, so the final result is 17,179,869,184. This is the total number of cells in an Excel worksheet. The formula below uses the range 1:1048576 to achieve the same result:
=ROWS(1:1048576)*COLUMNS(1:1048576) // returns 17179869184
Tip: Excel will enter the range 1:1048576 for you if you click the upper-left corner of the spreadsheet while entering a formula.
If you find the ROWS + COLUMNS formula cumbersome, you can try the formula below which is based on the COUNTA function:
This formula is a bit of a hack. The COUNTA function will count cells that contain numbers, text, or errors. It will not count empty cells. If we use COUNTA with the range itself, we get a result of 82, since the range contains 9 empty cells:
=COUNTA(B4:H16) // returns 82
However, when we add zero:
The match operation will cause Excel to evaluate the empty cells as zeros, and Excel will return a combination of numbers and errors. In this example, the array created inside COUNTA looks like this:
Notice that empty cells are now represented by zeros, and cells that contain text are represented by errors. Because all cells represented by the array have a value, COUNTA will now return the same result as the original formula above, 91.
Caution: this formula will work fine on fine on typical size ranges. However, the performance will suffer on very large ranges, and you might notice a delay when the formula is entered or recalculated.