# Highlight cells that contain one of many

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

To highlight cells that contain one of many text strings, you can use a formula based on the functions ISNUMBER and SEARCH, together with the SUMPRODUCT function. In the example shown, the conditional formatting applied to B4:B11 is based on this formula:

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

Working from the inside out, this part of the formula searches each cell in B4:B11 for all values in the named range "things":

The SEARCH function returns the position of the value if found, and and the #VALUE error if not found. For B4, the results come back in an array like this:

{8;#VALUE!;#VALUE!}

The ISNUMBER function changes all results to TRUE or FALSE:

{TRUE;FALSE;FALSE}

The double negative in front of ISNUMBER forces TRUE/FALSE to 1/0:

{1;0;0}

The SUMPRODUCT function then adds up the results, which is tested against zero:

=SUMPRODUCT({1;0;0})>0

Any non-zero result means at least one value was found, so the formula returns TRUE, triggering the rule.

### Ignore empty things

To ignore empty cells in the named range "things", you can try a modified formula like this:

=SUMPRODUCT(--ISNUMBER(SEARCH(IF(things<>"",things),B4)))>0

This works as long as the text values you are testing don't contain the string "FALSE". If they do, you can extend the IF function to include a value if false known not to occur in the text (i.e. "zzzz", "####", etc.)

### Case-sensitive option

SEARCH is not case-sensitive. To check case as well, replace SEARCH with FIND like so:

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

### Preventing false matches

One problem with this approach is you may see false matches caused by substrings that appear inside longer words. For example, if you try to match "dr" you may also find "Andrea", "drink", "dry", etc. since "dr" appears inside these words. This happens because SEARCH automatically performs a "contains" match.

For an partial fix, you can add space around the search words (i.e. " dr ", or "dr ") to avoid catching "dr" in another word. But this will fail if "dr" appears first or last in a cell, or appears next to punctuation. This can be partially addressed by adding space also around the original text. To add space to the start and end of both at the same time, you can try a formula like this:

=SUMPRODUCT(--ISNUMBER(FIND(" "&things&" "," "&B4&" ")))>0

However, this won't fix problems caused by punctuation.

If you need a more complete solution, one option is to normalize the text first in a helper column, taking care to also add a leading and trailing space. Then you can search for whole words surrounded by spaces.

## 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.