Excel Formula Contains Specific Text? How To
In this article
This article explains how to write an Excel formula that checks whether a cell contains specific text, returning TRUE or FALSE (or a custom result) based on the match. You enter the text you’re looking for and the cell range to search, and the formula tells you if that text appears anywhere within the cell. The core functions involved are ISNUMBER and SEARCH, with IF used when you want a custom output instead of TRUE/FALSE.
in search_text | Text to find | - | apple | 0 in cell_ref | Cell to search | - | A2 | 0 out result | Contains text? | - | IF(ISNUMBER(SEARCH(search_text, cell_ref)), "Yes", "No") | 0
Formula
The standard formula to test if a cell contains specific text is:
=IF(ISNUMBER(SEARCH("text", cell)), "Yes", "No")
In words: SEARCH looks for the text inside the cell and returns the position (a number) where it finds it. If the text is not found, SEARCH returns the #VALUE! error. ISNUMBER then checks whether SEARCH’s result is a number (meaning the text was found) and returns TRUE or FALSE. Finally, IF converts that TRUE/FALSE into whatever you want—here, “Yes” or “No”.
Variables:
- text – the specific text you’re looking for, in double quotes (e.g., "apple").
- cell – the cell reference you want to check (e.g., A2).
If you just need a TRUE/FALSE result, you can skip the IF and use =ISNUMBER(SEARCH("text", cell)) directly.
Worked Example
Using the calculator’s default values: search for “apple” in cell A2.
- Start with
SEARCH("apple", A2). If A2 contains “I ate an apple today”, SEARCH returns 9 (the position where “apple” starts). If A2 contains “banana”, SEARCH returns#VALUE!. - Wrap with
ISNUMBER(...). For “I ate an apple today”, ISNUMBER(9) returns TRUE. For “banana”, ISNUMBER(#VALUE!) returns FALSE. - Apply
IF(...). With TRUE, the result is “Yes”; with FALSE, the result is “No”.
So for the default inputs, if A2 contains the word “apple” anywhere, the output is “Yes”. If it doesn’t, the output is “No”.
When to Use This Formula
Use this formula when you need to:
- Filter or flag rows based on partial text matches (e.g., all cells containing “urgent”).
- Check if a cell contains a keyword before performing another calculation.
- Create conditional formatting rules that highlight cells containing specific words.
- Clean data by identifying entries that include certain codes or names.
It works for both exact words and partial matches. For example, searching for “app” will match “apple”, “application”, and “appetizer”.
How to Choose Between SEARCH, FIND, and COUNTIF
Excel offers several ways to check for text, and the right one depends on your needs:
- SEARCH – Case-insensitive, allows wildcards (* and ?). Best for general text checks where you don’t care about capitalization.
- FIND – Case-sensitive, no wildcards. Use when “Apple” and “apple” should be treated differently.
- COUNTIF – Counts cells in a range that match a condition. For a single cell,
=COUNTIF(A2,"*apple*")>0gives TRUE/FALSE. It’s simpler but less flexible if you need to return custom text.
For most cases, SEARCH is the most versatile. If you need case sensitivity, swap SEARCH for FIND in the same formula.
Common Mistakes and How to Avoid Them
- Forgetting the asterisks with COUNTIF –
COUNTIF(A2,"apple")only matches exact whole cell content. Use"*apple*"to match any cell containing “apple”. - Using quotes incorrectly – The search text must be in double quotes, e.g.,
"apple". If you reference a cell containing the text, use the cell reference without quotes:SEARCH(B1, A2). - Case sensitivity surprises – SEARCH is not case-sensitive, so “Apple” and “apple” both match. If you need exact case, use FIND.
- Searching for wildcard characters – If you want to find a literal asterisk or question mark, you must precede it with a tilde (~). For example,
SEARCH("~*", A2)finds cells containing an asterisk.
Limitations and Alternatives
The SEARCH/ISNUMBER approach works for a single cell. If you need to check an entire range for the presence of text, use COUNTIF or SUMPRODUCT. For more advanced pattern matching, consider using regular expressions (available in Excel via VBA or the newer REGEXTEST function in some versions).
Also note that SEARCH returns the position of the first occurrence only. If you need to find all occurrences or extract text after a match, you’ll need additional functions like MID or TEXTSPLIT.
Frequently Asked Questions
How do I check if a cell contains one of several texts?
Use a formula like =IF(SUMPRODUCT(--ISNUMBER(SEARCH({"apple","banana","cherry"},A2)))>0,"Yes","No"). This checks for each text in the array and returns TRUE if any match.
Can I use this formula for partial matches like “starts with”?
Yes. For “starts with”, use SEARCH("text", cell)=1 to check if the text appears at the beginning. For “ends with”, use SEARCH("text", cell)=LEN(cell)-LEN("text")+1.
Why does my formula return #VALUE! instead of FALSE?
That happens if you use FIND (which is case-sensitive) and the text isn’t found, or if you don’t wrap SEARCH with ISNUMBER. Always use ISNUMBER(SEARCH(...)) to avoid the error.
Is there a way to make the search case-insensitive?
SEARCH is already case-insensitive. If you want case-sensitive, use FIND instead. For example, =ISNUMBER(FIND("apple",A2)) will only match lowercase “apple”.
Can I use wildcards in SEARCH?
Yes, SEARCH supports wildcards: * (any sequence) and ? (single character). For example, SEARCH("a*e", A2) matches “apple”, “axe”, and “ale”.
How do I count how many cells in a range contain specific text?
Use =COUNTIF(range,"*text*"). This counts all cells in the range that contain the text anywhere. For case-sensitive counting, you’d need an array formula with FIND.