Smart Systems for Home

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

Excel IF Contains: How to Check for Text in Cells

· 4 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

Excel does not have a native "IF CONTAINS" function, but you can achieve this result by combining the IF, ISNUMBER, and SEARCH (or FIND) functions. This formula checks if a specific text string exists within a cell and returns one value if it does, and another if it does not. It is case-insensitive when using SEARCH and case-sensitive when using FIND.

What You'll Need

  • A Microsoft Excel workbook with data containing text strings.
  • The specific keyword or phrase you want to search for.
  • Basic understanding of Excel formula syntax.

Step-by-Step

  1. Identify your target cell: Determine which cell contains the text you want to check. For example, assume the text is in cell A1.
  2. Define the search term: Decide what word or phrase you are looking for. Let's say you are searching for the word "urgent".
  3. Construct the SEARCH function: Type =SEARCH("urgent", A1). The SEARCH function looks for the first argument within the second argument. If found, it returns the position number; if not found, it returns an error (#VALUE!). Note that SEARCH is case-insensitive, so "Urgent" and "urgent" are treated the same.
  4. Wrap with ISNUMBER: To convert the result into a TRUE/FALSE logical test, wrap the previous step in ISNUMBER. The formula becomes =ISNUMBER(SEARCH("urgent", A1)). This returns TRUE if the text is found and FALSE if it is not.
  5. Add the IF statement: Finally, use the IF function to return custom values. Use the structure =IF(logical_test, value_if_true, value_if_false). Your complete formula will look like this: =IF(ISNUMBER(SEARCH("urgent", A1)), "Yes", "No").
  6. Enter and copy the formula: Press Enter to apply the formula to the current cell. Drag the fill handle down to apply the logic to other rows in your dataset.

Common Mistakes

One frequent error is confusing SEARCH with FIND. While both locate text, FIND is case-sensitive. If you need to distinguish between "Apple" and "apple," use FIND instead of SEARCH. Another common mistake is forgetting to enclose the search term in double quotes if it is typed directly into the formula. If the search term is stored in another cell (e.g., B1), do not use quotes around the cell reference.

Users also often overlook wildcard support. The SEARCH function supports wildcards like * (any sequence of characters) and ? (any single character). If you are trying to find a literal asterisk or question mark, you must escape them with a tilde (~). For example, to find a literal "?", use SEARCH("~?", A1).

Tips

For better readability and maintenance, consider using named ranges. Instead of referencing A1, name the range "EmailSubject" and use =IF(ISNUMBER(SEARCH("urgent", EmailSubject)), "Flag", "Normal"). This makes formulas easier to understand when shared with others.

If you are working with large datasets, note that array formulas involving text searches can be resource-intensive. In modern versions of Excel (Office 365 and Excel 2021+), you can use the TEXTSPLIT or XLOOKUP functions for more advanced scenarios, but the ISNUMBER(SEARCH()) combination remains the most compatible and widely used method for simple containment checks.

You can also nest multiple conditions. For example, to check if a cell contains either "urgent" OR "high priority," use: =IF(OR(ISNUMBER(SEARCH("urgent", A1)), ISNUMBER(SEARCH("high priority", A1))), "Action Required", "None").

Troubleshooting

If your formula returns an unexpected error, check the following:

  • #VALUE! Error: This usually means the SEARCH function did not find the text. Ensure the spelling of the search term matches exactly (ignoring case if using SEARCH). Also, verify there are no hidden spaces in the source data. Use the TRIM function on the source cell to remove leading/trailing spaces.
  • Formula returns FALSE when it should be TRUE: Check if you accidentally used FIND instead of SEARCH if the case matters. If the text is split across cells, ensure you are concatenating them correctly before searching.
  • Wildcards behaving unexpectedly: If you are searching for special characters like ~, *, or ?, remember they have special meanings in SEARCH. Escape them with a preceding tilde.
  • Cell references are wrong: Ensure the relative references adjust correctly when you copy the formula down. If you always want to compare against a fixed keyword, lock the reference (e.g., $B$1).

Frequently Asked Questions

Is the Excel IF CONTAINS formula case-sensitive?

No, if you use the SEARCH function inside the IF statement, it is case-insensitive. If you need case-sensitivity, replace SEARCH with FIND.

Can I search for multiple words at once?

Not directly in a single SEARCH function. You must combine multiple ISNUMBER(SEARCH()) tests using AND (for all words present) or OR (for any word present) operators within the IF function.

How do I highlight cells that contain specific text?

Use Conditional Formatting. Select your range, go to Home > Conditional Formatting > New Rule > Use a formula to determine which cells to format. Enter the formula =ISNUMBER(SEARCH("keyword", A1)) and set your desired format.

Does this work with numbers?

Yes, but Excel treats numbers differently than text. If you are searching for a number within a larger numeric string, ensure the cell is formatted as Text or use the TEXT function to convert the number to a string before searching, e.g., SEARCH("123", TEXT(A1, "0")).

Why does my formula show #N/A?

This typically happens if you are using VLOOKUP or similar lookup functions incorrectly in conjunction with text search. However, standard ISNUMBER(SEARCH()) formulas should not return #N/A unless the referenced cell contains an error itself. Check the source cell for errors.