Exceljet

Quick, clean, and to the point

If cell contains

Excel formula: If cell contains
Generic formula 
=IF(ISNUMBER(SEARCH("abc",A1)),A1,"")
Summary 

To test for cells that contain certain text, you can use a formula that uses the IF function together with the SEARCH and ISNUMBER functions.  In the example shown, the formula in C5 is:

=IF(ISNUMBER(SEARCH("abc",B5)),B5,"")
To test only for "if cell equals" you don't need ISNUMBER or SEARCH.
Explanation 

One limitation if the IF function is that it does not support wildcards like "?" and "*". This means you can't use IF by itself to test for text that may appear anywhere in a cell.

One solution is a formula that uses the IF function together with the SEARCH and ISNUMBER functions. In the example shown, we have a list of email addresses, and we want to extract those that contain "abc". In  C5, the formula were using is this:

=IF(ISNUMBER(SEARCH("abc",B5)),B5,"")

If "abc" is found anywhere in cell B5, IF will return that value. If not, IF will return an empty string (""). In this formula, the logical test is this bit:

ISNUMBER(SEARCH("abc",B5))

This snippet will return TRUE if the the value in B5 contains "abc" and false if not. The logic of ISNUMBER + SEARCH is explained in detail here

To copy cell the value in B5 when it contains "abc", we provide B5 again for the "value if true" argument. If FALSE, we supply an empty string ("") which will display as a blank cell on the worksheet.

Author 
Dave Bruns

Excel Formula Training

Formulas are the key to getting things done in Excel. In this accelerated training, you'll learn how to use formulas to manipulate text, work with dates and times, lookup values with VLOOKUP and INDEX & MATCH, count and sum with criteria, dynamically rank values, and create dynamic ranges. You'll also learn how to troubleshoot, trace errors, and fix problems. Instant access. See details here.

Download 200+ Excel Shortcuts

Get over 200 Excel shortcuts for Windows and Mac in one handy PDF.

Excel foundational video course
Excel Pivot Table video training course
Excel formulas and functions video training course
Excel Charts video training course
Video training for Excel Tables
Dynamic Array Formulas