Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel IF Formula: Check If a Cell Contains Text

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To check whether a cell contains specific text, wrap a text search in IF and return a result: in Excel, =IF(COUNTIF(A2,"*text*")>0,"Yes","No") is the simplest pattern, and in either Excel or Google Sheets, =IF(ISNUMBER(SEARCH("text",A2)),"Yes","No") works everywhere and ignores case. COUNTIF with asterisks is the most reliable because it matches the text anywhere in the cell rather than only at the start. The two formulas look similar but behave differently, and picking the right one avoids most of the errors beginners hit.

What You'll Need

  • Excel (Microsoft 365, 2019 or later) or Google Sheets, or LibreOffice Calc. The functions used here exist in all three.
  • A column of text values to test, for example product names, addresses, notes or order references.
  • An empty column to the right of your data for the result, so you do not overwrite anything.
  • Familiarity with the equals sign: every formula begins with = and is typed into a cell, not into a toolbar.

Formula labels and menus can differ slightly by version and platform, but the function names and syntax below are stable across Excel and Sheets.

Step-by-Step

  1. Set up a test column. Put your data in column A starting at row 2, with a header in A1 such as "Description". Leave column B empty for the flag.
  2. Pick your method. Use COUNTIF when you want a simple contains check and your data lives in Excel or Sheets. Use SEARCH or FIND when you need to know the position of the match, or need to combine the test with other logic.
  3. Write the COUNTIF version. In B2 type =IF(COUNTIF(A2,"*shirt*")>0,"Match","No match"). The asterisks are wildcards meaning "anything before and after", so any cell containing the letters s-h-i-r-t in that order returns Match. Note that COUNTIF is not case-sensitive: "Shirt" and "SHIRT" both match.
  4. Write the SEARCH version instead if you prefer. In B2 type =IF(ISNUMBER(SEARCH("shirt",A2)),"Match","No match"). SEARCH looks for the text anywhere inside A2 and returns a number when found; ISNUMBER converts that to TRUE or FALSE, which IF turns into your chosen labels. If SEARCH finds nothing it returns an error, and ISNUMBER quietly turns that error into FALSE, giving "No match".
  5. Choose the case-sensitive variant. If "Shirt" should match but "shirt" should not, replace SEARCH with FIND: =IF(ISNUMBER(FIND("Shirt",A2)),"Match","No match"). FIND respects capital letters.
  6. Replace the hard-coded word with a cell reference. Rather than editing the formula for each keyword, put the search term in a separate cell, say D1, and write =IF(ISNUMBER(SEARCH(D1,A2)),"Match","No match"). Change D1 and every result updates.
  7. Return something more useful than Yes/No. Swap the labels for a number, a category or a reference: =IF(ISNUMBER(SEARCH("refund",A2)),"Billing","Other"), or point to another cell with B2.
  8. Copy the formula down. Drag the fill handle at the bottom-right of B2 down the column, or double-click it, so relative references update row by row. Confirm a couple of rows by eye.
  9. Test the edge cases deliberately. Include a blank cell, a cell with the word at the very start, one at the very end, one in uppercase and one with extra spaces. All should behave as intended before you rely on the column.
  10. Search for several words at once if needed. For "contains any of these", nest: =IF(SUMPRODUCT(--ISNUMBER(SEARCH({"shirt","dress","hat"},A2)))>0,"Apparel","Other"). For "contains all", use AND with two ISNUMBER tests.

Common Mistakes

  • Forgetting the wildcards. =IF(A2="shirt",...) only matches a cell whose entire content is exactly "shirt". Any surrounding text fails.
  • Using = when you meant contains. A comparison with = is exact; contains needs COUNTIF with asterisks, SEARCH or FIND.
  • Expecting case sensitivity from SEARCH or COUNTIF. Both ignore case. Only FIND is case-sensitive, and it rejects wildcards.
  • Typing the search word without quotes. SEARCH(shirt,A2) makes Excel look for a named range called shirt, which does not exist, and returns a #NAME? error.
  • Confusing a match number with a position. SEARCH returns the character position, not a count. A result of 1 means the text is at the very beginning.
  • Leaving stray spaces. A trailing space in the keyword or the data breaks an otherwise correct match. Wrap both sides in TRIM when the data is pasted from elsewhere.

Tips

  • Use an asterisk as a wildcard for any number of characters and a question mark for exactly one, so "*hat?" matches "hats" but not "hat" on its own.
  • To test for a literal asterisk or question mark, put a tilde in front of it, as in "~*".
  • You can match numbers stored as text: search for the digits as a string, such as SEARCH("2024",A2).
  • If you want a highlight rather than a label, use conditional formatting with a formula rule such as =ISNUMBER(SEARCH("shirt",$A2)) applied to the whole column.
  • Keep the keyword list on a separate sheet and reference it, so the formula stays readable when the list grows.
  • Convert the result column to plain values with paste-special before sorting or sharing, so the flags do not recalculate unexpectedly.

Troubleshooting

Every result says "No match" when the text is clearly there. Check for leading or trailing spaces, hidden characters, or a literal reading of a wildcard. Test the keyword by itself in a blank cell; if SEARCH returns a number there, the formula is fine and the data needs TRIM or CLEAN.

You see #VALUE! or #N/A. An error is leaking through because you skipped ISNUMBER. SEARCH returns #VALUE! when nothing is found, so always wrap it: IF(ISNUMBER(SEARCH(...)),...).

You see #NAME?. A function or name is misspelled, or a keyword is missing its quotation marks. Retype the word in quotes and confirm the function name by starting to type it and letting the suggestion list appear.

Partial matches you did not want. Searching "cat" also matches "category" and "concatenate". Add spaces around the keyword, or search for a longer, more specific term.

The formula copied down points at the wrong cells. The references were locked with dollar signs when they should not be, or vice versa. Use $A2 for a fixed column that changes per row and $D$1 for a fixed keyword.

A row that should match does not, in Google Sheets only. Sheets and Excel both support COUNTIF wildcards, but a very old shared file may have a setting that changes wildcard behaviour. Switching to the ISNUMBER/SEARCH form sidesteps the issue entirely.

Nothing works after editing. Press Ctrl+Z (Cmd+Z on Mac) to undo, then rebuild the formula one piece at a time in a blank cell: just the SEARCH, then wrap it in ISNUMBER, then wrap that in IF. The step where the result stops making sense is your problem.

Frequently Asked Questions

Is COUNTIF or SEARCH better for a contains check?

COUNTIF with asterisks is shorter and easier to read, and works in both Excel and Sheets. SEARCH is more flexible when you want the position of the match or want to combine it with other logic such as LEFT or MID.

How do I check for text that ignores case?

Use SEARCH or COUNTIF. Both ignore case automatically. Use FIND only when casing must match exactly.

Can I test for more than one keyword at once?

Yes. Use SUMPRODUCT with an array of keywords and ISNUMBER/SEARCH to return true if any one of them appears, or combine separate ISNUMBER tests with AND to require all of them.

Why does my formula match a longer word?

Because contains-style matching finds the letters anywhere in the string, so "cat" matches "category". Search for the whole word with spaces around it, or use an exact comparison with =.

Does this work on a Mac or in Google Sheets?

Yes. The function names and arguments are the same. Only the keyboard shortcuts differ, and the fill handle behaves the same way.

Can I return the matching text rather than a flag?

Yes, point the IF result at the source cell: =IF(ISNUMBER(SEARCH("shirt",A2)),A2,"") copies the full cell content when it matches and leaves it blank otherwise.