Summary

Excel does not provide a dedicated "contains" function to test a cell for one or more text strings. However, you can use the LAMBDA function to create a custom function for this purpose. In the example below, the formula in cell C5 is:

=ContainsOneOfMany(B5,{"red","blue","green"})

This formula will return TRUE if a cell contains any one of the strings passed into it. Because it is built with the SEARCH function, it automatically performs partial matching and supports wildcards.

Generic formula

=LAMBDA(text,strings,SUM(--ISNUMBER(SEARCH(strings,text)))>0)

Explanation 

Excel does not provide a dedicated "contains" function, but you can create a custom function to test if a cell contains one or many strings with the LAMBDA function. LAMBDA functions do not require VBA, but are only available in Excel 365.

The first step in creating a custom LAMBDA function is to verify the logic needed with a Excel standard formula. This LAMBDA formula is based on a Excel formula created with three functions: SUMPRODUCT, ISNUMBER, and SEARCH:

=SUMPRODUCT(--ISNUMBER(SEARCH(things,A1)))>0

Read a detailed description here. Because the LAMBDA function is only available in the dynamic array version of Excel, which handles array formulas natively, we are using SUM instead of SUMPRODUCT (see note below), and renaming "things" to "strings" to make the formula arguments a bit more natural:

=SUM(--ISNUMBER(SEARCH(strings,A1)))>0 // base formula

The screen below shows this formula in use with three strings "red", "blue", and "green":

The standard Excel formula in action

This formula returns TRUE for any cell in column B that contains any one of the strings "red", "blue", or "green".

The next step is to convert this formula into a generic (unnamed) LAMBDA formula. We will need two input parameters, one for the text, and one for the strings to test. These need to appear as the first arguments in the LAMBDA formula. The final argument contains the calculation to perform, which is adapted from our standard Excel formula above. Here is the generic LAMBDA:

=LAMBDA(text,strings,SUM(--ISNUMBER(SEARCH(strings,text)))>0)

The screen below shows this formula in action, with the testing syntax needed to provide values for text and strings:

=LAMBDA(text,strings,SUM(--ISNUMBER(SEARCH(strings,text)))>0)(B5,{"red","blue","green"})

Testing the generic LAMBDA formula

Note that results are the same as above. The next step in creating a custom LAMBDA is to name and define the formula with the Name Manager. In this case, we'll use the name "ContainsOneOfMany":

LAMBDA version defined in Name Manager

Finally, we update the worksheet to use the new custom function, and confirm that results are the same:

Custom LAMBDA function in action

Notes

Although we are hard-coding the strings "red", "blue", and "green" as an array constant in this example for simplicity, the formula will work fine if we supply a range instead:

=ContainsOneOfMany(A1,range)

In addition, the formula will also work correctly if we supply only one string:

=ContainsOneOfMany(A1,"red")

Note: Traditionally, SUMPRODUCT is often seen in array formulas, because it can handle arrays natively, without control + shift + enter. This makes the formula "more friendly" to most users. The SUM function can also be used in these cases, but the formula must then be entered with control + shift + enter. In Excel 365, the SUM function will work in these cases without any special handling. Since LAMBDA is only available in Excel 365, this example uses SUM, since SUMPRODUCT provides no additional benefit.

Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.