# Excel formula for Beginners – How to Count cells that contain specific text in Excel

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.

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

# Personal Career & Learning Guide for Data Analyst, Data Engineer and Data Scientist

## Applied Machine Learning & Data Science Projects and Coding Recipes for Beginners

A list of FREE programming examples together with eTutorials & eBooks @ SETScholars

# Projects and Coding Recipes, eTutorials and eBooks: The best All-in-One resources for Data Analyst, Data Scientist, Machine Learning Engineer and Software Developer

Topics included: Classification, Clustering, Regression, Forecasting, Algorithms, Data Structures, Data Analytics & Data Science, Deep Learning, Machine Learning, Programming Languages and Software Tools & Packages.
(Discount is valid for limited time only) `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

Please do not waste your valuable time by watching videos, rather use end-to-end (Python and R) recipes from Professional Data Scientists to practice coding, and land the most demandable jobs in the fields of Predictive analytics & AI (Machine Learning and Data Science).

The objective is to guide the developers & analysts to “Learn how to Code” for Applied AI using end-to-end coding solutions, and unlock the world of opportunities!

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

Hierarchical Clustering with Python and Scikit-Learn

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