Count cells with text, COUNTIF function and wildcards

What to do if we want to count cells with text?

Count cells with text, COUNTIF func­tion and wildcards 

For me, the sim­plest solu­tion is using the COUNTIF func­tion and wild­cards. We have an aster­isk that rep­re­sents any text string, even an emp­ty one. We also have a ques­tion mark that rep­re­sents just one sin­gle sign (Fig. 1). 

 Wildcards
Fig. 1 Wildcards

Let’s start with count­ing all cells with text. First, we have to select a prop­er range and press the F4 key to lock it. Then, we have to write an aster­isk in dou­ble quotes so that it counts any text string, even an emp­ty one (Fig. 2). 

=COUNTIF($B$2:$B$11,”*”)

Proper range and an asterisk
Fig. 2 Prop­er range and an asterisk

And just like that we have 4 cells with text. In cell B6 I have past­ed an emp­ty text string and even if we see noth­ing, Excel counts it as a cell with an emp­ty text string. But, what can we do if we don’t want to count emp­ty text strings? We can copy our for­mu­la and add a ques­tion mark next to the aster­isk. It does­n’t mat­ter if it’s before or after the sign (Fig. 4).

=COUNTIF($B$2:$B$11,”?*”)

Formula modification
Fig. 4 For­mu­la modification

This way we count­ed all cells that have at least one sign (Fig. 5). 

Results
Fig. 5 Results

If we want to count all not emp­ty cells, we can change our cri­te­ria to the <> signs (Fig. 6). 

=COUNTIF($B$2:$B$11,”<>”)

Adding <> signs
Fig. 6 Adding <> signs

How­ev­er, the sim­plest solu­tion in most cas­es would be using the COUNTA func­tion, where we don’t have to wor­ry about any cri­te­ria (Fig. 7). 

=COUNTA(B2:B11)

COUNTA function
Fig. 7 COUNTA function

https://www.youtube.com/watch?v=8ywd-H7ALc8

Count all cells containing certain text | Excel Tips #27

Some­times, we need to count all cells con­tain­ing cer­tain text. In our exam­ple, it will be a prod­uct name. 

Count all cells con­tain­ing cer­tain text | Excel Tips #27

Let’s assume that we want to count all cells con­tain­ing the name of eggs. In the In the bas­ket col­umn, we have cells where the name of eggs appears at the begin­ning, in the mid­dle, or at the end of the text. Some­times, the cell con­tains only eggs (Fig. 1). 

Eggs in many locations
Fig. 1 Eggs in many locations

In Excel, it’s a sim­ple task because we have the COUNTIF func­tion, where we can use wild­cards. Let’s start writ­ing the func­tion. We have to select a range, which is the In the bas­ket col­umn, F4 to lock it, then let’s write cri­te­ria. If we want to count only cells that con­tain only the word eggs, we would write D2 in the cri­te­ria, how­ev­er, we want to count the cells which con­tain eggs and oth­er prod­ucts as well. That’s why we have to add a wild­card, i.e. an aster­isk (*) that replaces any num­ber of char­ac­ters, even an emp­ty text string. So, we’re putting the aster­isk in dou­ble quotes, then we’re writ­ing an amper­sand to com­bine it with eggs, then D2, where eggs are. As we can see, eggs can be placed also at the end, that’s why we have to com­bine it with anoth­er aster­isk in dou­ble quotes. Our cri­te­ria look as fol­lows (Fig. 2). 

=COUNTIF($B$2:$B$20,”*”&D2&”*”

Our criteria
Fig. 2 Our criteria

When we press the F9 key, we can see how our cri­te­ria real­ly look (Fig. 3). 

=COUNTIF($B$2:$B$20,”*Eggs*”

Our criteria after F9
Fig. 3 Our cri­te­ria after F9

By press­ing Ctrl + Z, let’s return to the pre­vi­ous ver­sion, and close our for­mu­la (Fig. 4). 

=COUNTIF($B$2:$B$20,”*”&D2&”*”)

Our whole formula
Fig. 4 Our whole formula

After enter­ing and copy­ing the for­mu­la down, we can see how many cells con­tain cer­tain prod­uct (Fig. 5). 

Results
Fig. 5 Results

https://www.youtube.com/watch?v=Yv7Uiat–cs

COUNTIF function — how many times we sell apples

Today, we want to count how many times we sold apples, pears and oranges. We are going to use a small table to check our results, because with a big­ger table it isn’t going to be easy. We will use the COUNTIF func­tion. This func­tion has got only two argu­ments. The first one is a range, where we will be check­ing our con­di­tions or cri­te­ria. In our case, the cri­te­ri­on is the name of our prod­uct, so we are select­ing the cell with the prod­uct name. Such a func­tion will check each cell in the range, whether it con­tains the name or not.

COUNTIF func­tion — how many times we sell apples

=COUNTIF(B2:B10,F2)

COUNIF function
Fig. 1 COUNTIF function

If a cell con­tains the name, the func­tion will add 1 to the counter. We can see that there are four 1s. 

 Four 1s
Fig. 2 Four 1s

We also have to lock the range by press­ing the F4 key, so that it stays in the same place. Cri­te­ria, how­ev­er, should not be locked because we want them to change while copy­ing the for­mu­la down, i.e. we want a giv­en prod­uct to change.

=COUNTIF($B$2:$B$10,F2)

Locked range
Fig. 3 Locked range

After enter­ing and copy­ing down, we have our results. We can see that apples have been sold four times, pears three times and oranges two times. It will also work with big­ger tables. All we need to do is to write a big­ger range.

=COUNTIF($B$2:$B$10,F2)

Final results
Fig. 4 Final results

https://www.youtube.com/watch?v=krHpltXwMAk