Explanation

The goal is to do something if a cell contains a given substring.

If you are familiar with Excel, you will probably think first of the IF function.

However, one limitation of IF is that it doesnot support wildcardslike “?”

Searching for a character in a cell

and “*”.

This approach is explained below.

If SEARCH finds the text, it returns thepositionof the text as a number.

Searching for a character in a cell

If the text is not found, SEARCH returns a #VALUE error.

error for “z”, which is not found.

The screen below shows how the formulas above can be transferred to a workbook.

Searching for a character in a cell

error as in the last example, where the word “dog” is not found.

The screen below shows how the formulas can be set up in a spreadsheet.

The text to search is in column B.

Searching for a character in a cell

The word to search for is typed directly into the SEARCH function:

The formulas above work fine.

Enter the ISNUMBER function.

The SEARCH function doesn’t work by itself because it returns either a numeric position or an error.

Searching for a character in a cell

If SEARCHcan’tfind the text, it returns an error, and ISNUMBER returns FALSE.

We now have what we need to create an IF statement to find out if a cell contains text.

If “abc” is found anywhere in cell B5, SEARCH returns a number and ISNUMBER returns TRUE.

Searching for a word in a cell

The IF function then returns “x” as a final result.

If “abc” isnot found, SEARCH returns an error and ISNUMBER returns FALSE.

The IF function then returns an empty string ("") as a final result.

If cell contains “abc” return value

If FALSE, we supply an empty string ("") which will display as a blank cell.

If the count is a positive number, the IF function will evaluate the number as TRUE.

More than one condition can be tested by nesting IF functions.

Excel formula: Cell contains specific text

SEARCH returns the position offind_textinsidewithin_textas a number.

The IF function

Excel formula: If cell equals

Excel formula: Cell contains one of many things

Excel formula: If cell contains one of many things

Excel formula: Filter text contains

Excel formula: Cell contains specific words

Excel IF function

Excel SEARCH function

Excel ISNUMBER function

Article image