Skip to content

How to return a value if a cell contains text in Excel and Google Sheets

Topic:IF, IFS & nested conditions
Excel & Google Sheets
=IF(ISNUMBER(SEARCH("apple",A2)),"Contains apple","Does not contain")

Verified example

Computed by a real spreadsheet engine on the sample data below.

ProductFlag
apple juice
orange soda
apple cider
mango drink

=IF(ISNUMBER(SEARCH("apple",A2)),"Contains apple","Does not contain")Contains apple

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1Start with SEARCH to locate the text: SEARCH("apple",A2) returns the position number when "apple" appears anywhere in A2, and a #VALUE! error when it does not. SEARCH is case-insensitive.
  2. 2Wrap it in ISNUMBER to convert that to TRUE/FALSE: ISNUMBER(SEARCH("apple",A2)) is TRUE when the text is present.
  3. 3Wrap in IF to return your values: =IF(ISNUMBER(SEARCH("apple",A2)),"Contains apple","Does not contain").
  4. 4To return something other than fixed text, put a cell reference or formula in the IF branches: =IF(ISNUMBER(SEARCH("apple",A2)),B2,"") returns the matching row’s price instead of a label.
  5. 5For a case-sensitive check, swap SEARCH for FIND: =IF(ISNUMBER(FIND("Apple",A2)),"Match","No match") — FIND("Apple",…) will not match "apple".
  6. 6Copy the formula down the column; each row evaluates independently.

Tips

Working on a sheet you inherited? Run the Auditor on the whole file first — it flags every #REF!, #N/A, broken column pattern, and inconsistent formula in seconds, free, no signup.

Frequently asked

Why use ISNUMBER instead of just SEARCH?

SEARCH returns a #VALUE! error when the text is not found, not FALSE — so IF cannot use it directly. ISNUMBER maps "found" (a number) to TRUE and "not found" (an error) to FALSE.

How do I make the check case-sensitive?

Use FIND instead of SEARCH: =IF(ISNUMBER(FIND("Apple",A2)),"Match","No match"). FIND distinguishes upper and lower case; SEARCH does not.

How do I check for multiple keywords at once?

Wrap several ISNUMBER(SEARCH(…)) tests in OR (any keyword) or AND (all keywords): =IF(OR(ISNUMBER(SEARCH("apple",A2)),ISNUMBER(SEARCH("pear",A2))),"Fruit","Other").

Can I use wildcards instead of SEARCH?

Inside COUNTIF/SUMIF/SUMIFS, yes: "*apple*" matches the word anywhere in the cell. IF itself does not accept wildcards in a plain comparison, which is why the ISNUMBER(SEARCH(…)) pattern exists.

How do I return a value from another column when the text matches?

Point the IF branches at cells instead of strings: =IF(ISNUMBER(SEARCH("apple",A2)),B2,""). The row’s value in column B is returned only for matching rows.

More on IF, IFS & nested conditions

See all →

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: