Count cells that contain specific text
The COUNTIF function counts cells in a range that meet criteria. For example, to count the number of cells in a range that contain "a" you can use:
=COUNTIF(range,"a") // exact match
However, note this is an exact match. In order to be counted, a cell must contain exactly "a". If the cell contains any other characters, it will not be counted.
For the problem shown, we want to count cells that contain specific text, meaning the text could be anywhere in the cell. To do this, we need to use the asterisk (*) character as a wildcard. For example, to count cells that contain the letter "a" anywhere we use:
The asterisk in a formula means "match any number of characters, including zero", so this pattern will count any cell that contains "a" in any position, with or without other characters to the left or right. The formulas used in the example all follow the same pattern:
Note: COUNTIF is not case-sensitive.
With a cell reference
You can easily adjust this formula to use the contents of another cell for the criteria. For example, if A1 contains the text you want to match, you can use:
Count specific numbers
The COUNTIF formula above won't work if you are looking for a particular number and cells contain numeric data. This is because the wildcard automatically causes COUNTIF to look for text only (i.e. to look for "2" instead of just 2). Because a text value won't ever be found in a true number, COUNTIF will return zero.
In this formula, text is the text you are looking for, and range is the range of cells you want to count. When SEARCH locates a match, it will return a number, and the ISNUMBER function will convert the number to a TRUE or FALSE value. Because we are checking more than one cell, the result will be an array or TRUE and FALSE values. The double-negative is used to convert the TRUE and FALSE values to 1s and 0s, and the SUMPRODUCT function will return the sum of the array as a final result.
SEARCH automatically treats all numbers as text, so it will find, for example, the 1 in the number 201. Also, there's no need to use wildcards to indicate position, because SEARCH will automatically look through all text in a cell.
For a case-sensitive count, you can use a formula based on the FIND function:
Here, the FIND function is used instead of SEARCH, because FIND is case-sensitive. In other respects the formula works like the ISNUMBER + FIND formula described above.