Smart Systems for Home

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

Excel IF String in String: How to Find Text in a Cell

· 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 if a specific string exists within another string in Excel, use the combination of IF, ISNUMBER, and SEARCH functions: =IF(ISNUMBER(SEARCH("text", A1)), "Yes", "No"). This formula works because SEARCH looks for the position of the text; if it finds it, it returns a number, which ISNUMBER validates as TRUE, triggering the IF statement to return your specified positive result.

What You'll Need

  • A computer with Microsoft Excel installed (works across all modern versions including Excel 365, 2021, 2019, and 2016).
  • A dataset containing the text strings you wish to analyze.
  • Basic familiarity with how to enter formulas into an Excel cell.

Step-by-Step

  1. Identify Your Target Data: Locate the column containing the long strings of text (the "haystack") and decide what specific word or phrase (the "needle") you are looking for. For example, if cell A2 contains "Red Apple Fruit" and you want to find the word "Apple".
  2. Start the IF Function: Click on the cell where you want the result to appear (e.g., B2). Type =IF(. The IF function requires three parts: a logical test, the value if true, and the value if false.
  3. Insert the SEARCH Function: Inside the logical test area of the IF function, type ISNUMBER(SEARCH("your_text", A2)).
    • The SEARCH("your_text", A2) part tells Excel to look for the specific string inside cell A2. If it finds it, it returns the character position (e.g., if "Apple" starts at the 5th character, it returns 5). If it does not find it, it returns a #VALUE! error.
    • The ISNUMBER() function wraps around the SEARCH function. This is critical because the IF function cannot handle the #VALUE! error directly. ISNUMBER converts a numeric position into "TRUE" and an error into "FALSE".
  4. Define Your Output Values: After closing the ISNUMBER parenthesis, add a comma, then the text you want to see if the string is found, another comma, and the text for when it is not found. For example: =IF(ISNUMBER(SEARCH("Apple", A2)), "Found", "Not Found").
  5. Close and Execute: Close the final parenthesis and press Enter.
  6. Apply to the Entire Column: Hover your mouse over the bottom-right corner of the cell (the fill handle) until it turns into a small black cross. Double-click or drag the handle down to apply the formula to all rows in your dataset.

Common Mistakes

One of the most frequent errors is forgetting the ISNUMBER wrapper. Many users try to use =IF(SEARCH("text", A1), "Yes", "No"). This fails because if the text is not found, SEARCH returns an error, and the IF function simply displays that error rather than the "No" result. You must convert the search result into a boolean TRUE or FALSE value first.

Another common mistake is confusing SEARCH with FIND. While they look identical in structure, SEARCH is case-insensitive (it treats "APPLE" and "apple" as the same), whereas FIND is case-sensitive. If you use FIND and your capitalization doesn't match perfectly, the formula will return "Not Found" even if the word is present.

Users also often forget to wrap their search text in double quotation marks. In Excel formulas, any literal text string must be enclosed in quotes (e.g., "Apple"). If you omit these, Excel thinks you are referring to a named range or a function, resulting in a #NAME? error.

Tips

Using Cell References: Instead of typing the search word directly into the formula, put the word you are looking for in a separate cell (e.g., D1). Change your formula to =IF(ISNUMBER(SEARCH($D$1, A2)), "Yes", "No"). The dollar signs create an absolute reference, meaning when you drag the formula down, it always looks at cell D1. This allows you to change your search term instantly without editing every formula in the column.

Searching for Multiple Strings: If you need to check if a cell contains "Apple" OR "Orange", you can wrap the logic in an OR function: =IF(OR(ISNUMBER(SEARCH("Apple", A2)), ISNUMBER(SEARCH("Orange", A2))), "Match", "No Match"). This expands the capability to find any one of several keywords.

Handling Case Sensitivity: If you specifically need to find a string only when it matches the case (e.g., finding "iPhone" but ignoring "iphone"), replace SEARCH with FIND. The syntax remains exactly the same: =IF(ISNUMBER(FIND("iPhone", A2)), "Match", "No Match").

Wildcards in SEARCH: The SEARCH function supports wildcards. The question mark (?) matches any single character, and the asterisk (*) matches any sequence of characters. This is useful for finding patterns rather than exact words.

Troubleshooting

If your formula is returning #VALUE!, check to see if you omitted the ISNUMBER function. The SEARCH function is designed to return an error when no match is found; ISNUMBER is the only way to catch that error and turn it into a usable "FALSE" value for the IF statement.

If the formula returns "Not Found" but you can clearly see the word in the cell, check for leading or trailing spaces. A cell that looks like " Apple" might behave differently depending on the search term. You can wrap your target cell in the TRIM function to remove excess spaces: =IF(ISNUMBER(SEARCH("Apple", TRIM(A2))), "Yes", "No").

If you are getting a #NAME? error, check your quotation marks. Ensure you are using standard straight quotes (") and not "curly" or "smart" quotes often produced by word processors like Microsoft Word. Excel does not recognize curly quotes as string delimiters.

If the formula is returning "Yes" for everything, ensure your search string is not empty. If you use a cell reference for the search term (like $D$1) and that cell is blank, SEARCH may return 1 for every cell, leading ISNUMBER to return TRUE for every row.

Frequently Asked Questions

Can I use this to find a string and then return a value from another column?

Yes. Instead of putting "Yes" or "No" in the IF function, you can reference another cell. For example: =IF(ISNUMBER(SEARCH("Apple", A2)), C2, ""). This will return the value of cell C2 if "Apple" is found, and leave the cell blank if it is not.

Does this work for numbers stored as text?

Yes. The SEARCH function treats everything it looks at as a string. If you are searching for the number "123" within a cell that contains "Order 12345", the formula will successfully identify it as a match.

Is there a way to count how many times a string appears in a cell?

The IF/ISNUMBER/SEARCH method only tells you if a string exists at least once. To count occurrences, you need a different approach: =(LEN(A2)-LEN(SUBSTITUTE(A2, "text", "")))/LEN("text"). This calculates the difference in length before and after removing the target word.

Can I search for a string across multiple cells at once?

The standard IF/SEARCH combination works on a cell-by-cell basis. To check a whole range, you can use the COUNTIF function with wildcards: =IF(COUNTIF(A2:A100, "*Apple*")>0, "Found in Range", "Not Found"). The asterisks act as wildcards to find the text anywhere in the cell.

What happens if the search string is exactly the same as the cell content?

The formula will still return "Yes". SEARCH finds the string regardless of whether it is a small part of a larger sentence or the entire content of the cell.