How-to recipes · Text

How to check if a cell contains a word in Excel

Test whether a cell contains specific text with SEARCH and ISNUMBER, make it case-sensitive with FIND, check several words, or match whole words only.

Beginner SEARCH FIND ISNUMBER IF COUNTIF OR REGEXTEST IFS

Support messages, product descriptions, bank transaction texts and survey answers are free text. To sort them into categories you need to know whether a cell contains a particular word: does the message mention refund, does the transaction text include Amazon, does the description contain organic? Excel has no CONTAINS function, but a combination of two functions does the job in every version, and Microsoft 365 adds a regular-expression test for whole words.

The example data

Four customer messages in A2:A5. We want Yes in column B when the message mentions a refund.

B2fx=IF(ISNUMBER(SEARCH("refund",A2)),"Yes","No")
AB
1MessageRefund?
2Refund request for order 5512Yes
3Login problem
4Customer wants a REFUND
5Refundable deposit question

SEARCH finds refund at position 1, ISNUMBER turns the position into TRUE, IF shows Yes.

Result: Yes

  1. SEARCH looks for the word inside the cell and returns its position (a number), or the #VALUE! error if it is not there.
  2. ISNUMBER converts the result into TRUE (found) or FALSE (not found), so the error disappears.
  3. IF turns TRUE/FALSE into words of your choice. If you only need TRUE/FALSE for filtering, leave the IF out.

SEARCH ignores case, so REFUND in row 4 is found too. Put the word in a cell, for example D1, to make the formula reusable: =ISNUMBER(SEARCH($D$1,A2)).

Microsoft 365: the whole column

B2fx=IF(ISNUMBER(SEARCH("refund",A2:A5)),"Yes","No")
AB
1MessageRefund?
2Refund request for order 5512Yes
3Login problemNo
4Customer wants a REFUNDYes
5Refundable deposit questionYes

One formula returns a result for every message. Note that Refundable also counts.

Case-sensitive check: FIND

FIND works exactly like SEARCH but respects upper and lower case: =ISNUMBER(FIND("REFUND",A2)) is TRUE only for row 4. FIND also treats wildcards as normal characters, while SEARCH understands ? and *.

Alternative: COUNTIF with wildcards

=COUNTIF(A2,"*refund*")>0 returns TRUE when the cell contains the word anywhere. It is short and familiar, but it works only on text (not on numbers) and is limited to 255 characters in the criteria. COUNTIF is more useful when you count matching cells across a range; see How to count cells that contain text in Excel.

Any of several words

Give SEARCH a list of words in an array constant and wrap the result in OR:

Formula
=OR(ISNUMBER(SEARCH({"refund","return","money back"},A2)))

This returns TRUE if at least one word appears. To require all words, replace OR with AND. In Excel 2016 and 2019, array constants inside SEARCH work without Ctrl+Shift+Enter when the whole formula returns a single value as here.

Whole words only

SEARCH finds refund inside Refundable (row 5). If that is wrong for you, test for the word as a whole. In current Microsoft 365, REGEXTEST with the word boundary \b does it: =REGEXTEST(A2,"\brefund\b",1) (the 1 makes it case-insensitive). For the four messages it returns TRUE, FALSE, TRUE, FALSE. In older versions, pad the text and the word with spaces: =ISNUMBER(SEARCH(" refund "," "&A2&" ")). That simple version misses the word when it is followed by punctuation, such as refund.; replace common punctuation with spaces first if that matters.

Return a category instead of Yes/No

To label each message with the first matching topic, combine several tests with IFS (Excel 2019 and later):

Formula
=IFS(ISNUMBER(SEARCH("refund",A2)),"Billing",ISNUMBER(SEARCH("login",A2)),"Account",TRUE,"Other")

For many keywords, a two-column keyword table and a lookup is easier to maintain than a long formula.

Pitfalls

  • Empty search word. SEARCH with an empty text returns 1, so every cell "contains" it. Guard with =AND($D$1<>"",ISNUMBER(SEARCH($D$1,A2))).
  • Wildcards in SEARCH. ? and * are wildcards; to search for a real question mark use ~?.
  • Numbers. SEARCH works on numbers as text: =ISNUMBER(SEARCH("55",A2)) finds 55 in 5512.
  • Partial words are the most common surprise, as shown with Refundable. Decide whether that is acceptable.
Tip. To colour the matching rows instead of writing Yes/No, use the same test as a conditional formatting rule: How to use conditional formatting with a formula in Excel. Text functions are introduced in Text cleanup: TRIM, CLEAN, TEXTSPLIT, Flash Fill and Text to Columns.
⬇Practice workbookExamples with live formulas + practice sheets · .xlsx · 14 KB

More how-to recipes