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