# Count cells that contain specific text

=COUNTIF(range,"*txt*")

To count cells that contain certain text, you can use the COUNTIF function with a wildcard. In the example shown, the formula in E5 is:

=COUNTIF(B5:B15,"*a*")

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:

=COUNTIF(range,"*a*")

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:

=COUNTIF(range,"*"&A1&"*")

### 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.

To count a specific number in *numeric content*, you can use a different formula based on the SEARCH function and the ISNUMBER function like this:

=SUMPRODUCT(--(ISNUMBER(SEARCH(text,range))))

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.

### Case-sensitive version

For a case-sensitive count, you can use a formula based on the FIND function:

=SUMPRODUCT(--(ISNUMBER(FIND(text,range))))

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.

## Excel Formula Training

Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.

## Download 200+ Excel Shortcuts

Get over 200 Excel shortcuts for Windows and Mac in one handy PDF.