Count Cells That Contain Specific Text in Excel
In this article
To count cells that contain specific text, use the COUNTIF function combined with asterisks (*) as wildcards. For example, the formula =COUNTIF(A1:A10, "*text*") counts every cell in the range A1 through A10 that contains the word "text" anywhere within the cell. This method allows you to find partial matches rather than requiring the cell to match your search term exactly.
This technique is essential for analyzing large datasets where a cell might contain a full sentence or a list of items, but you only need to know how many times a specific keyword appears across your rows. Whether you are tracking project statuses, categorizing customer feedback, or auditing inventory lists, mastering wildcards transforms a basic count into a powerful search tool.
What You'll Need
- A spreadsheet application (Microsoft Excel, Google Sheets, or LibreOffice Calc).
- A dataset containing the text strings you wish to count.
- A basic understanding of how to enter a formula into a cell.
Step-by-Step
- Identify your data range: Determine which column or group of cells contains the text you want to analyze. For this guide, we will assume your data is in column A, from cell A1 to A100.
- Select the output cell: Click on the empty cell where you want the final count to appear.
- Enter the COUNTIF function: Type
=COUNTIF(into the cell. This function requires two arguments: the range of cells to search and the criteria to look for. - Define the range: Highlight the cells you identified in Step 1 or type the range manually. For example, type
A1:A100followed by a comma. Your formula should now look like=COUNTIF(A1:A100,. - Apply the wildcard criteria: To count any cell that contains the text (regardless of what comes before or after it), wrap your keyword in asterisks and double quotation marks.
- If searching for the word "Complete", type
"*Complete*". - The formula now looks like:
=COUNTIF(A1:A100, "*Complete*").
- If searching for the word "Complete", type
- Complete the formula: Type the closing parenthesis
)and press Enter. The cell will now display the total number of cells containing that specific text. - (Optional) Link to a cell reference: If you want to change the search term without editing the formula, type your keyword into a different cell (e.g., C1). Then, use this formula:
=COUNTIF(A1:A100, "*" & C1 & "*"). The ampersand (&) symbols join the wildcards to the value in cell C1.
Common Mistakes
- Forgetting the Quotation Marks: Text criteria in Excel formulas must always be enclosed in double quotes. Writing
*text*without quotes will result in a #NAME? error. - Confusing "Contains" with "Exact Match": If you use
=COUNTIF(A1:A100, "Complete")without asterisks, Excel will only count cells that contain only the word "Complete." If a cell says "Task Complete," it will be ignored. - Incorrect Range References: Ensure the range is accurate. If you add new data below row 100, the formula
A1:A100will not include the new entries. You can useA:Ato select the entire column. - Overlooking Hidden Spaces: While wildcards usually bypass this, if you are doing an exact match search, a trailing space (e.g., "Complete ") will prevent the cell from being counted.
Tips
- Case Sensitivity: By default,
COUNTIFis not case-sensitive. Searching for"*complete*"will find "Complete", "COMPLETE", and "complete". - Using the Question Mark Wildcard: If you need to find a specific number of characters, use a question mark (
?). For example,"???"counts cells that contain exactly three characters. - Counting Multiple Keywords: To count cells that contain either "Red" OR "Blue", add two COUNTIF functions together:
=COUNTIF(A1:A100, "*Red*") + COUNTIF(A1:A100, "*Blue*"). - Excluding Text: To count cells that do not contain specific text, use the "not equal to" operator:
=COUNTIF(A1:A100, "<>*Complete*").
Troubleshooting
If the formula returns 0 or an error, try these steps in order:
- Check for Syntax Errors: Ensure every opening parenthesis has a closing one and that commas are correctly separating the range and the criteria.
- Verify Quotation Marks: Ensure you are using standard straight quotes (
") rather than "smart" or curly quotes (“) which often occur when copying from word processors. - Check Data Types: Ensure the cells you are searching are formatted as "Text" or "General." If a cell is formatted as a date or a number, the text search may not behave as expected.
- Test with a Simple Value: Try a basic formula like
=COUNTIF(A1:A100, "Complete")to see if the issue is with the wildcards or the range itself.
Frequently Asked Questions
Can I count cells that start with specific text?
Yes. Place the asterisk only at the end of the text: =COUNTIF(A1:A100, "Start*"). This counts cells that begin with "Start" regardless of what follows.
Can I count cells that end with specific text?
Yes. Place the asterisk only at the beginning of the text: =COUNTIF(A1:A100, "*End"). This counts cells that finish with "End" regardless of what precedes it.
Does this work for numbers?
The asterisk wildcard is designed for text. To count numbers based on specific criteria (like "greater than 50"), use =COUNTIF(A1:A100, ">50"). For partial number matches, you may need to convert the numbers to text first.
How do I count cells containing any text at all (ignoring blanks)?
Use the asterisk by itself in quotes: =COUNTIF(A1:A100, "*"). This counts all cells containing any string of text while ignoring empty cells.
Can I use this to count cells containing multiple different keywords in the same cell?
A single COUNTIF cannot check for two different strings in one cell using "AND" logic. To count cells that contain both "Red" AND "Blue", use =COUNTIFS(A1:A100, "*Red*", A1:A100, "*Blue*").