Hits: 12

# (Excel examples for Beginners)

In this end-to-end excel example, you will learn – How to Count cells that contain specific text in Excel.

# How to Count cells that contain specific text in Excel

### Generic formula

=COUNTIF(range,"*txt*")

### Explanation

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*")

### How this formula works

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:

=COUNTIF(B5:B15,"*a*") // contains "a" =COUNTIF(B5:B15,"*2*") // contains "2" =COUNTIF(B5:B15,"*-S*") // contains "-s" =COUNTIF(B5:B15,"*x*") // contains "x"

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

Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause.The information presented here could also be found in public knowledge domains.

# Learn by Coding: v-Tutorials on Applied Machine Learning and Data Science for Beginners

Latest end-to-end Learn by Coding Projects (Jupyter Notebooks) in Python and R:

**All Notebooks in One Bundle: Data Science Recipes and Examples in Python & R****. **

**End-to-End Python Machine Learning Recipes & Examples.**

**End-to-End R Machine Learning Recipes & Examples.**

**Applied Statistics with R for Beginners and Business Professionals**

**Data Science and Machine Learning Projects in Python: Tabular Data Analytics**

**Data Science and Machine Learning Projects in R: Tabular Data Analytics**

**Python Machine Learning & Data Science Recipes: Learn by Coding**

**R Machine Learning & Data Science Recipes: Learn by Coding**

**Comparing Different Machine Learning Algorithms in Python for Classification (FREE)**

There are 2000+ End-to-End Python & R Notebooks are available to build **Professional Portfolio as a Data Scientist and/or Machine Learning Specialist**. All Notebooks are only $29.95. We would like to request you to have a look at the website for FREE the end-to-end notebooks, and then decide whether you would like to purchase or not.

Excel formula for Beginners – How to Filter text contains in Excel

Excel formula for Beginners – How to Count numbers by range with COUNTIFS in Excel