Quick, clean, and to the point

if cell contains this or that

Excel formula: if cell contains this or that
Generic formula 

To check to see if a cell contains more than one substring, you can use a formula based on the COUNTIF function.

In the example shown, the formula in C5 is:


The core of this formula is COUNTIF, which returns zero if none of the substrings is found, and a positive number if at least one substring is found. The twist in this case is that we are giving COUNTIF more than one substring to look for in the criteria, supplied as an "array constant". As a result, COUNTIF will return an array of results, with one result per item in the original criteria.

Note that we are also using the asterisk (*) as a wildcard for zero or more characters on either side of the substrings. This is what allows COUNTIF to count the substrings anywhere in the text (i.e. this provides the "contains" behavior).

Because we are getting back an array from COUNTIF, we use the SUM function to sum all items in the array. The result goes into the IF function as the "logical test". Any positive number will be evaluated as TRUE, so you can supply any values you like for value if true and value if false.

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 100+ Important Excel Functions

Get over 100 Excel Functions you should know 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