To check if a cell contains text in Excel, use =IF(ISNUMBER(SEARCH("text",A2)),"Yes","No"). It returns "Yes" when A2 contains the word anywhere inside it, and "No" when it does not.
Excel has no single "contains" function, and =IF(A2="text","Yes","No") only works when the whole cell is exactly that text. The formulas below handle the real question: does the cell include this text somewhere. In every example, A2 is the cell being checked and the formula sits in B2, ready to fill down. Change the references and the search text to fit your sheet.
Which formula should you use?
| Goal | Formula | Case sensitive |
|---|---|---|
| Contains one word | =IF(ISNUMBER(SEARCH("text",A2)),"Yes","No") | No |
| Contains one word, wildcard version | =IF(COUNTIF(A2,"*text*")>0,"Yes","No") | No |
| Contains any of two words | =IF(OR(ISNUMBER(SEARCH("red",A2)),ISNUMBER(SEARCH("blue",A2))),"Yes","No") | No |
| Contains any word from a list | =IF(SUMPRODUCT(--ISNUMBER(SEARCH($D$2:$D$4,A2)))>0,"Yes","No") | No |
| Whole cell equals the text, case sensitive | =IF(EXACT(A2,"Text"),"Yes","No") | Yes |
Excel IF cell contains text: the SEARCH and ISNUMBER formula
=IF(ISNUMBER(SEARCH("apple",A2)),"Yes","No")
The formula has three layers, and it is easier to trust once you see what each one returns.
SEARCH(find_text, within_text, [start_num])looks forfind_textinsidewithin_textand returns the position of the first character of the match.SEARCH("apple","green apple pie")returns 7. If the text is not there, Microsoft documents that SEARCH returns the#VALUE!error.ISNUMBERreturns TRUE for a number and FALSE for text. Position 7 is a number, so you get TRUE. The#VALUE!error is not a number, so the result is FALSE. Microsoft's page does not spell out the error case for ISNUMBER, but it is the behaviour this formula pattern relies on, and the same pattern appears in the sibling article on checking a value against a list.IF(logical_test, value_if_true, [value_if_false])picks the label. Microsoft lists the third argument as optional, but give it explicitly so the "no" case is not an unexplained FALSE.
Example output, with the formula filled down from B2:
| A (cell) | B (formula result) |
|---|---|
| green apple pie | Yes |
| APPLE JUICE | Yes |
| banana bread | No |
| (empty) | No |
Notice that "APPLE JUICE" matched. SEARCH ignores case, according to Microsoft's documentation.
Why not put SEARCH straight into IF?
Writing =IF(SEARCH("apple",A2),"Yes","No") looks shorter, and it works when the text is found, because any position of 1 or more counts as TRUE. When the text is missing, SEARCH returns #VALUE! and IF passes the error through, so the cell shows an error instead of "No". The ISNUMBER wrapper is what turns the not-found case into a clean FALSE.
Wildcards inside SEARCH
SEARCH treats ? as any single character and * as any run of characters. To look for a literal question mark or asterisk, put a tilde in front of it, for example SEARCH("~?",A2). This matters if you are checking for text such as "what?" or a footnote marker like *, which would otherwise match nearly everything.
Searching from a cell instead of typing the text
Hard-coded text in a formula is awkward to change. Put the search word in a cell, say E1, and lock the reference with dollar signs:
=IF(ISNUMBER(SEARCH($E$1,A2)),"Yes","No")
Now you can type a different word into E1 and every row updates. If E1 is empty, SEARCH looks for an empty string, which matches at position 1, so every non-empty cell returns "Yes". Guard against that if the input cell might be blank: =IF($E$1="","",IF(ISNUMBER(SEARCH($E$1,A2)),"Yes","No")).
Check if a cell contains text with COUNTIF and wildcards
=IF(COUNTIF(A2,"*apple*")>0,"Yes","No")
COUNTIF(range, criteria) counts the cells in the range that match the criteria. Pointing it at the single cell A2 gives 1 or 0. The asterisks on both sides mean "any characters before and after", so the cell only has to include the word. Microsoft documents both wildcards and states that COUNTIF is not case sensitive.
To take the search text from E1, join it to the wildcards with the ampersand:
=IF(COUNTIF(A2,"*"&$E$1&"*")>0,"Yes","No")
This version is a little shorter than SEARCH when you only need one word. SEARCH is the better default for two reasons. It also gives you the position of the match, which you can use with MID or LEFT when you need to extract text. And COUNTIF has a documented limit: Microsoft states it returns incorrect results when matching strings longer than 255 characters. Long cells, such as notes or pasted paragraphs, are better handled by SEARCH.
Check if a cell contains one of several words
For two or three words, test each one and combine the tests with OR:
=IF(OR(ISNUMBER(SEARCH("red",A2)),ISNUMBER(SEARCH("blue",A2))),"Yes","No")
OR returns TRUE if any argument is TRUE, and FALSE only when all of them are FALSE. Microsoft's page says it accepts up to 255 conditions. Use AND in place of OR when the cell must contain every word, not just one.
Past three or four words this gets long, and the words are buried in the formula. Put them in a range instead, here D2:D4, and let SUMPRODUCT count the hits:
=IF(SUMPRODUCT(--ISNUMBER(SEARCH($D$2:$D$4,A2)))>0,"Yes","No")
SEARCH runs once for every word in the range and returns a list of positions and errors. ISNUMBER turns that list into TRUE and FALSE, the double minus -- converts those to 1 and 0, and SUMPRODUCT adds them up. If the total is above 0, at least one word from the list appears in A2. Microsoft's SUMPRODUCT page shows it evaluating array expressions such as comparisons directly, so this does not need a special array-entry step. Adding a word to the list needs no formula edit, and you can extend the range to $D$2:$D$20 to leave room.
One trap: a blank cell inside the list counts as an empty search string, which matches everything. Keep the list range tight, with no empty cells.
Check if a cell contains text, case sensitive
SEARCH and COUNTIF ignore case. For whole-cell comparisons where case matters, EXACT is documented as case sensitive:
=IF(EXACT(A2,"Apple"),"Yes","No")
EXACT(text1, text2) returns TRUE only when both strings are identical, so "Apple" matches "Apple" but not "apple". It also treats spaces as characters, so "Apple " with a trailing space is different. Formatting such as bold or font colour is ignored.
EXACT compares entire cells, so it does not answer "contains". For a case-sensitive contains check, Microsoft's SEARCH page points to the FIND function as the case-sensitive counterpart. That function is not covered by the sources used here, so check its syntax in Excel's function help before relying on it.
Return something other than Yes or No
The two result arguments of IF can be any value, including another formula. Some practical variations:
- Tag rows by category:
=IF(ISNUMBER(SEARCH("invoice",A2)),"Billing","Other"). - Leave the cell blank when there is no match:
=IF(ISNUMBER(SEARCH("urgent",A2)),"Check",""). Two quotation marks with nothing between them give an empty text result. - Return a number for later maths:
=IF(ISNUMBER(SEARCH("paid",A2)),1,0), then total the column withSUM. - Several categories in order: nest IF inside IF, for example
=IF(ISNUMBER(SEARCH("invoice",A2)),"Billing",IF(ISNUMBER(SEARCH("refund",A2)),"Refunds","Other")). Microsoft's IF page says you can nest multiple IF functions but does not state a limit, so keep nesting shallow for readability.
Count or highlight cells that contain text
To count how many cells in a column contain a word, skip IF and use COUNTIF directly:
=COUNTIF(A2:A100,"*apple*")
To highlight those cells, use conditional formatting with a formula rule. On the Home tab choose Conditional Formatting, then New Rule, then "Use a formula to determine which cells to format", and enter =ISNUMBER(SEARCH("apple",$A2)) with the rule applied to your range. The rule formula is written for the first cell of the range, and the dollar sign before the column letter keeps it pointing at column A as it applies across the range.
If the formula gives the wrong answer
- Every row says "Yes". The search text is empty, for example a blank reference cell, or the list contains a blank cell. An empty search string matches every cell.
- A row says "No" but the word is there. Check for a different spelling, a non-breaking space or a hyphen in place of a space.
=LEN(A2)shows the real length of the cell, and=TRIM(A2)strips extra spaces. - Odd matches with
?or*. These are wildcards in both SEARCH and COUNTIF. Put a tilde before them to match the literal character. - The cell holds a number. SEARCH works on text, but Excel converts a number to text for the search, so
SEARCH("23",A2)finds it inside 1234. Whether you want that depends on your data. - Results shift when you fill down. A list range typed as
D2:D4moves one row per row. Lock it as$D$2:$D$4.
If what you actually need is to test whether a whole value appears in a column, rather than a fragment inside one cell, see Excel check if value is in list, which covers COUNTIF, MATCH and XLOOKUP for that case.
Frequently asked questions
- How do I check if a cell contains specific text in Excel?
- Use =IF(ISNUMBER(SEARCH("text",A2)),"Yes","No"). SEARCH returns the position of the text inside A2, or a #VALUE! error if it is not there. ISNUMBER turns that into TRUE or FALSE, and IF turns it into the labels you want.
- Is the Excel SEARCH function case sensitive?
- No. Microsoft documents SEARCH as ignoring case, so "Apple" and "APPLE" both match "apple". Microsoft's SEARCH page names FIND as the function to use for a case-sensitive search. For a case-sensitive whole-cell comparison, EXACT is documented as case sensitive.
- Why does IF with SEARCH return #VALUE! instead of my label?
- SEARCH returns #VALUE! when the text is not found, and an error passed straight to IF makes the whole formula an error. Wrap SEARCH in ISNUMBER, as in =IF(ISNUMBER(SEARCH("text",A2)),"Yes","No"), so the not-found case becomes FALSE.
- Can I use a wildcard instead of SEARCH?
- Yes, with COUNTIF: =IF(COUNTIF(A2,"*text*")>0,"Yes","No"). The asterisk matches any run of characters, and COUNTIF ignores case. Microsoft warns that COUNTIF returns incorrect results for strings longer than 255 characters.