To count cells that contain specific text in Excel, use the COUNTIF function with wildcards: for a partial match, enter =COUNTIF(range,"*text*"); for an exact match, use =COUNTIF(range,"text"). For case-sensitive counting, use SUMPRODUCT with ISNUMBER and FIND. This guide walks through each method, plus common pitfalls and troubleshooting.
What You'll Need
- Excel 2010 or later (Windows or Mac) or Excel for the web. The functions used here are available in all modern versions.
- A worksheet with text data in a column or row.
- Basic familiarity with entering formulas and selecting ranges.
Step-by-Step
- Identify your range. Select the cells you want to search, for example A2:A100. You can also use a whole column reference like A:A, but limit it to the data area for speed.
- Decide on exact vs. partial match. Exact match counts cells whose entire content equals the text. Partial match counts cells that contain the text anywhere. This choice determines the formula.
- For an exact match, enter:
=COUNTIF(A2:A100,"apple"). This counts cells equal to "apple" (case-insensitive). - For a partial match, enter:
=COUNTIF(A2:A100,"*apple*"). The asterisks are wildcards meaning any characters before or after. This counts "apple", "pineapple", "apple pie", etc. - To count cells that start with the text, use
=COUNTIF(A2:A100,"apple*"). To count cells that end with it, use=COUNTIF(A2:A100,"*apple"). - For case-sensitive counting, use
=SUMPRODUCT(--ISNUMBER(FIND("Apple",A2:A100))). FIND is case-sensitive, so this counts only cells containing "Apple" with a capital A. Note: SUMPRODUCT with full-column references can be slow; use a bounded range. - To count multiple different texts, add separate COUNTIF formulas:
=COUNTIF(A2:A100,"apple")+COUNTIF(A2:A100,"banana"). For an OR condition with partial matches, use=SUMPRODUCT(--(ISNUMBER(SEARCH({"apple","banana"},A2:A100))))but be aware this counts a cell once per matching term if it contains both; adjust with a helper column if needed. - Press Enter to see the result. If you see a formula error, check that the range and text are correctly quoted.
- Copy the formula down or across if you need counts for multiple categories. Use absolute references (e.g., $A$2:$A$100) if the range should stay fixed.
Common Mistakes
- Forgetting wildcards for partial matches. Without asterisks, COUNTIF looks for an exact match, so "apple" won't count "apple pie".
- Using COUNTIF for case-sensitive counts. COUNTIF ignores case, so "Apple" and "apple" are treated the same. Use SUMPRODUCT with FIND for case sensitivity.
- Including header rows. If your range includes a header like "Fruit", it may match your search text and inflate the count. Start the range at the first data row.
- Mismatched quotes. Text criteria must be in double quotes. If you use a cell reference for the criteria, don't put quotes around the reference:
=COUNTIF(A2:A100,B1). - Wildcards in the text itself. If you need to search for a literal asterisk or question mark, precede it with a tilde:
~*or~?. - Using SUMPRODUCT with entire columns. This can cause performance issues; always use a specific range.
Tips
- Use SEARCH instead of FIND for case-insensitive partial matches with SUMPRODUCT:
=SUMPRODUCT(--ISNUMBER(SEARCH("apple",A2:A100))). - To count cells that contain text but not a specific word, combine COUNTIF with subtraction: total text cells minus the specific count.
- For dynamic criteria, put the search term in a cell and reference it:
=COUNTIF(A2:A100,"*"&B1&"*"). - Use Excel Tables (Ctrl+T) so ranges auto-expand as you add data.
- Remember COUNTIF is not case-sensitive; if case matters, always use SUMPRODUCT with FIND.
- Test your formula on a small sample first to confirm it behaves as expected.
Troubleshooting
If your count is zero when you expect a match, check for leading or trailing spaces in the cells. Use TRIM in a helper column or adjust the criteria to include wildcards around spaces. If the count is higher than expected, verify the range doesn't include headers or other columns. If you get a #VALUE! error, ensure the range is a single column or row, not a multi-column block, for COUNTIF. For SUMPRODUCT errors, confirm all ranges are the same size. If wildcards aren't working, check that the cell format is text, not a formula returning text with hidden characters. If the formula is slow, reduce the range size or convert to an Excel Table. If you're on Excel for the web, some functions like SUMPRODUCT with array constants may behave differently; test with a small range.
Frequently Asked Questions
Can COUNTIF count cells that contain multiple different words?
Not directly. You need to add separate COUNTIF formulas or use SUMPRODUCT with multiple SEARCH conditions. Be careful not to double-count cells that contain more than one of the words.
How do I count cells that contain text but exclude blanks?
Use =COUNTIF(A2:A100,"?*") to count cells with at least one character, which excludes blanks. Or use =COUNTA(A2:A100)-COUNTBLANK(A2:A100).
Is there a way to count case-sensitive matches without SUMPRODUCT?
You can use =SUM(--EXACT("Apple",A2:A100)) entered as an array formula (Ctrl+Shift+Enter in older Excel). In Excel 365, dynamic arrays handle it without the special entry.
Why does COUNTIF count "apple" when I search for "Apple"?
COUNTIF is case-insensitive by design. To force case sensitivity, use SUMPRODUCT with FIND or EXACT.
Can I count cells with specific text across multiple columns?
COUNTIF works on a single range. For multiple columns, use =COUNTIF(A2:A100,"*text*")+COUNTIF(B2:B100,"*text*") or combine ranges with SUMPRODUCT and a condition.
What if my text contains wildcard characters like * or ?
Escape them with a tilde: ~* for a literal asterisk, ~? for a literal question mark. For example, =COUNTIF(A2:A100,"~*apple~").