How to Use Contains in Excel
In this article
Yes, you can check if a cell contains specific text using the SEARCH or FIND functions combined with ISNUMBER, or simply the IF function with a wildcard. This is useful for filtering data, flagging errors, or separating lists based on keywords without altering the original data.
What You'll Need
- A computer with Microsoft Excel installed (Excel 2013 or later is recommended for the best compatibility with modern functions).
- A spreadsheet with data where you want to perform the check.
- A basic understanding of cell references (like A1 or B2) and how to type formulas starting with an equals sign.
Step-by-Step
The most robust way to find text within a cell in Excel is to use a combination of the SEARCH function and the IF function. This method allows you to return a specific result (like "Yes" or "No") if the text is found, and a different result if it is not.
- Locate the cell where you want the result to appear. This is typically the cell adjacent to the data you are checking, or a blank cell where you want a summary. Click on this cell to select it.
- Type the equals sign (
=). This tells Excel you are about to enter a formula or function. Do not press Enter yet. - Type the
IFfunction. Start typingIF(. Excel will suggest the function; select it from the list. The formula structure will look like this:=IF(logical_test, [value_if_true], [value_if_false]). - Create the logical test. The logical test asks a question that Excel can answer with "Yes" or "No" (technically,
TRUEorFALSE). To check if cell A1 contains the word "apple", you will use theSEARCHfunction. Type the following inside the parentheses:SEARCH("apple", A1). Your formula should now look like=IF(SEARCH("apple", A1). - Complete the logical test syntax. The
SEARCHfunction returns a number (the position of the text) if found, or a#VALUE!error if not found. To make this a simple check, wrap the search in theISNUMBERfunction. AddISNUMBER(SEARCH("apple", A1))after the opening parenthesis of theIF. The full logical test is nowISNUMBER(SEARCH("apple", A1)). - Specify the result if true. Type a comma
,to separate the logical test from the result if true. For example, type"Found". This tells Excel to display the word "Found" if the search is successful. - Specify the result if false. Type another comma
,followed by the result if false. For example, type"Not Found". This tells Excel to display the word "Not Found" if the search fails. - Close the parentheses. Type
)twice to close both theIFandISNUMBERfunctions. The final formula should look like this:=IF(ISNUMBER(SEARCH("apple", A1)), "Found", "Not Found"). - Press Enter. Excel will calculate the result based on the data in cell A1. If A1 contains "apple pie", the cell will say "Found". If A1 contains "orange juice", the cell will say "Not Found".
- Drag the fill handle. If you have a list of data in column A, click the bottom-right corner of the cell with your formula and drag it down. Excel will apply the formula to every cell in the column, checking each one for the keyword "apple".
Common Mistakes
- Forgetting to wrap SEARCH in ISNUMBER. If you simply type
=IF(SEARCH("apple", A1), "Found"), Excel will treat any positive number (like the position 1) as True. However, if the text is not found, Excel returns an error, causing your formula to return#VALUE!instead of your "Not Found" text. TheISNUMBERwrapper converts the error into a False, ensuring your "Not Found" statement works correctly. - Using FIND instead of SEARCH. The
FINDfunction is case-sensitive and does not allow wildcards.SEARCHis case-insensitive and allows wildcards (like*or?), making it generally more useful for general text searching unless you specifically need to match capitalization. - Nesting too many functions. While it is possible to nest multiple IF statements, it can make the formula unreadable and difficult to debug. If you need to check for multiple keywords, it is often better to use the
ORfunction or split the logic into helper columns.
Tips
- Use wildcards for partial matches. You can use
*to represent any number of characters and?to represent a single character within the quotation marks of theSEARCHfunction. For example,SEARCH("*pie", A1)will find any cell containing "pie" at the end, such as "apple pie" or "blueberry pie". - Check for exact matches using COUNTIF. If you only want to check if the cell contains the exact word (and not part of a larger word), you can use the
COUNTIFfunction. The formula=COUNTIF(A1,"*apple*")will return 1 if the word "apple" appears anywhere in the cell, and 0 if it does not. You can then use this result directly in anIFformula or simply hide the column if the result is 0. - Highlighting cells with Conditional Formatting. You do not always need a formula to see results. You can use Conditional Formatting to highlight cells that contain specific text. Go to the Home tab, select New Rule, choose "Use a formula to determine which cells to format", and enter
=ISNUMBER(SEARCH("apple", A1)). Set your formatting style (like a background color) and click OK. Excel will now color any cell containing "apple" automatically.
Troubleshooting
- The formula returns
#VALUE!. This usually happens if the cell you are searching (A1) is empty or contains an error itself. Ensure the cell you are searching contains valid text data. If you are searching for a number (like 123) inside a text cell, theSEARCHfunction may fail. Ensure the data types match or wrap the search in anIFERRORfunction to handle the error gracefully. - The formula returns a number instead of text. If you omitted the
ISNUMBERwrapper in step 5, theIFfunction sees the number (the position of the text) as True and returns your "Found" text. This is actually a valid result, but if you want to see the actual position, you can simply remove theISNUMBERwrapper from the logical test. - The formula does not update when data changes. Ensure that "Automatic Calculation" is enabled. Go to the Formulas tab in the ribbon and ensure the "Calculation Options" button is not set to "Manual". If it is set to Manual, press F9 to refresh the calculations.
Frequently Asked Questions
How do I check if a cell contains any of several words?
You can use the OR function to combine multiple SEARCH functions. For example, =IF(OR(ISNUMBER(SEARCH("apple", A1)), ISNUMBER(SEARCH("banana", A1))), "Fruit", "Other") will return "Fruit" if the cell contains either word.
Does the SEARCH function count spaces?
Yes, the SEARCH function counts spaces as characters. If you are searching for a word in a cell that has extra spaces at the beginning or end, you should use the TRIM function on the cell reference, like SEARCH("apple", TRIM(A1)), to ensure the search is accurate.
Can I use this on a Mac?
Yes, the SEARCH, IF, and ISNUMBER functions are standard across Windows and Mac versions of Excel. The keyboard shortcuts and menu locations may vary slightly, but the formula syntax remains exactly the same.
What is the difference between SEARCH and FIND?
The main difference is that SEARCH is not case-sensitive and allows wildcards, while FIND is case-sensitive and does not allow wildcards. Use SEARCH for general text searches and FIND when you need to match the exact capitalization of the text.
How do I make the search case-insensitive?
The SEARCH function is already case-insensitive. It will find "Apple", "APPLE", and "apple" all as the same result. If you specifically need to enforce capitalization, you must use the FIND function instead.