Google Spreadsheet COUNTIF Contains Text Guide
In this article
To count cells that contain specific text in Google Sheets, use the COUNTIF function combined with wildcards. The most effective formula is =COUNTIF(range, "*text*"), where the asterisks act as placeholders for any characters appearing before or after your target word. This allows the function to find the text regardless of where it is positioned within the cell, making it ideal for searching through descriptions, notes, or mixed-data columns.
What You'll Need
- A Google account with access to Google Sheets.
- A dataset containing the text strings you wish to count.
- Basic familiarity with selecting cell ranges (e.g., A1:A100).
Step-by-Step
- Identify Your Data Range: Locate the column or group of cells you want to search. For example, if your product list is in column B from row 2 to row 50, your range is
B2:B50. - Select the Output Cell: Click on the empty cell where you want the final count to appear.
- Enter the Equals Sign: Type
=to tell Google Sheets you are starting a formula. - Input the COUNTIF Function: Type
COUNTIF(. This opens the function that counts cells based on a single criterion. - Define the Range: Type the range identified in step 1 (e.g.,
B2:B50) followed by a comma. - Apply the Wildcard Criterion: To find cells that contain specific text, you must wrap the text in double quotes and asterisks. For example, if you want to count every cell that contains the word "Urgent", type
"*Urgent*". The formula should now look like:=COUNTIF(B2:B50, "*Urgent*"). - Close and Execute: Type the closing parenthesis
)and press Enter. Google Sheets will immediately return the number of cells that contain that specific string of text. - Using a Cell Reference (Optional): If you want to be able to change the search term without editing the formula, type the search term in a separate cell (e.g., D1). Then, use the formula
=COUNTIF(B2:B50, "*"&D1&"*"). The ampersand symbols join the wildcards to the value inside cell D1.
Common Mistakes
One of the most frequent errors is forgetting the double quotes around the criterion. In Google Sheets, any text used directly inside a formula must be enclosed in quotes; otherwise, the spreadsheet thinks you are trying to reference a named range or a function, resulting in a #NAME? error.
Another common mistake is omitting the asterisks. If you use =COUNTIF(B2:B50, "Urgent"), the formula will only count cells that contain exactly the word "Urgent" and nothing else. If a cell says "Urgent Request" or "Very Urgent", it will be ignored. The wildcards are what turn an "exact match" search into a "contains" search.
Users also occasionally confuse the comma and semicolon. Depending on your regional settings (specifically in some European countries), Google Sheets uses a semicolon ; to separate arguments instead of a comma. If you receive a formula parse error, check if your region requires =COUNTIF(B2:B50; "*Urgent*").
Tips
Case Sensitivity: It is important to note that the standard COUNTIF function in Google Sheets is not case-sensitive. Searching for "*urgent*" will find "URGENT", "Urgent", and "uRgEnT". If you require a case-sensitive count, you will need to use a more complex formula involving the SUMPRODUCT and FIND functions, such as =SUMPRODUCT(--ISNUMBER(FIND("Urgent", B2:B50))).
Counting Multiple Keywords: If you need to count cells that contain either "Urgent" OR "Immediate", you can simply add two COUNTIF functions together: =COUNTIF(B2:B50, "*Urgent*") + COUNTIF(B2:B50, "*Immediate*"). However, be careful: if a single cell contains both words, it will be counted twice. To avoid double-counting, you may need to use a REGEXMATCH function within a SUMPRODUCT wrapper.
Excluding Specific Text: You can use the "not equal to" operator <> combined with wildcards to count cells that do not contain certain text. For example, =COUNTIF(B2:B50, "<>*Completed*") will count all cells that do not have the word "Completed" anywhere in the string.
Troubleshooting
If your formula is returning 0 when you know there are matches, first check for hidden characters. Sometimes data imported from other software contains non-breaking spaces or invisible formatting characters that interfere with matching. Try using the =TRIM() function on your data to remove leading and trailing spaces.
If you see a #VALUE! error, ensure that your range is valid. You cannot reference a range that doesn't exist or a range that spans across multiple sheets without using the proper sheet name syntax (e.g., 'Sheet1'!B2:B50). If you are referencing another sheet, ensure the sheet name is enclosed in single quotes if it contains spaces.
If the formula is returning a number that seems too high, check if you have duplicate entries or if your wildcard is too broad. For example, searching for "*art*" will count "Part", "Artist", "Heart", and "Department". To be more specific, you can add spaces inside the asterisks, such as "* art *", though this will only find the word when it is separated by spaces and not at the very beginning or end of the cell.
Frequently Asked Questions
Can I use this to count cells that start with specific text?
Yes. To count cells that start with specific text, place the asterisk only at the end of the string. For example, =COUNTIF(B2:B50, "Urgent*") will count cells starting with "Urgent" but will ignore cells where "Urgent" appears in the middle or end.
Can I count cells that end with specific text?
Yes. Place the asterisk only at the beginning of the string. For example, =COUNTIF(B2:B50, "*Urgent") will count cells that end with the word "Urgent" and ignore all others.
Does COUNTIF work with numbers if I use wildcards?
Wildcards only work with text strings. If your column contains numbers and you try to use "*123*", it may not work as expected because Google Sheets treats the number as a numeric value, not a string. To count numbers containing a specific digit, you may need to convert the range to text using the TO_TEXT function within a SUMPRODUCT formula.
How do I count cells containing any text at all (non-blank)?
To count any cell that contains any text regardless of what it is, use the wildcard "*". The formula =COUNTIF(B2:B50, "*") will count all cells in the range that contain at least one text character, effectively ignoring empty cells and cells containing only numbers.
Can I use a wildcard to find a single character?
Yes. While the asterisk * represents any number of characters, the question mark ? represents exactly one character. For example, =COUNTIF(B2:B50, "T?st") would count "Test" or "Tost", but not "Toast".