Count cells with text, COUNTIF function and wildcards
For me, the simplest solution is using the COUNTIF function and wildcards. We have an asterisk that represents any text string, even an empty one. We also have a question mark that represents just one single sign (Fig. 1).
Fig. 1 Wildcards
Let’s start with counting all cells with text. First, we have to select a proper range and press the F4 key to lock it. Then, we have to write an asterisk in double quotes so that it counts any text string, even an empty one (Fig. 2).
=COUNTIF($B$2:$B$11,”*”)
Fig. 2 Proper range and an asterisk
And just like that we have 4 cells with text. In cell B6 I have pasted an empty text string and even if we see nothing, Excel counts it as a cell with an empty text string. But, what can we do if we don’t want to count empty text strings? We can copy our formula and add a question mark next to the asterisk. It doesn’t matter if it’s before or after the sign (Fig. 4).
=COUNTIF($B$2:$B$11,”?*”)
Fig. 4 Formula modification
This way we counted all cells that have at least one sign (Fig. 5).
Fig. 5 Results
If we want to count all not empty cells, we can change our criteria to the <> signs (Fig. 6).
=COUNTIF($B$2:$B$11,”<>”)
Fig. 6 Adding <> signs
However, the simplest solution in most cases would be using the COUNTA function, where we don’t have to worry about any criteria (Fig. 7).
Today, we are going to talk about the COUNTA function. This function counts almost everything, It counts formula results (Fig. 1),
COUNTA Function counting almost everythingFig. 1 Formula results
numbers written as text (Fig. 2),
Fig. 2 Numbers written as text
dates and time (Fig. 3),
Fig. 3 Dates and time
logical values (Fig. 4),
Fig. 4 Logical values
numbers (Fig. 5),
Fig. 5 Numbers
and errors (Fig. 6).
Fig. 6 Errors
It even counts a single number or value that we put as an argument to COUNTA function (Fig. 7)
Fig. 7 A number put as an argument
Let’s write an array with four elements. It doesn’t matter how many columns of rows this array has, but it’s important how many elements there are. So, we have a range of two cells with numbers, a single value and four elements (Fig. 8).
Fig. 8 A range, a single value and four elements
Since COUNTA function counts every element, it returns 7 (Fig. 9)
Fig. 9 The function returned 7
However, there is one thing that the COUNTA function doesn’t count. It doesn’t cells that are really empty. Cell A14 is really empty, however cell B14 isn’t. It has got a formula that returns an empty text string. COUNTA function counts an empty text string (Fig. 10).
Fig. 10 Empty text string
Even if a formula returns a value from an empty cell (B15), the COUNTA function will count cell A15 because it has got a formula (Fig. 11)
Fig. 11 A cell with a formula
The formula in cell B14 was counted by the COUNTA function (Fig. 12)
Fig. 12 A cell with a formula
However, if we delete the formula, the COUNTA function will return 0 because cells A14 and B14 are now really empty (Fig. 13)
Fig. 13 Empty cells
Summing up, the COUNTA functions counts everything except for empty cells.