Quick, clean, and to the point

Count cells that contain either x or y

Excel formula: Count cells that contain either x or y
Generic formula 
=SUMPRODUCT(--((ISNUMBER(FIND("abc",rng)) +  ISNUMBER(FIND("def",rng)))>0))

To count cells that contain either x or y, you can use a formula based on the SUMPRODUCT function. In the example shown, the formula in cell F5 is:


This is the single cell formula solution, explained below. It is also possible to use a simpler formula based on a helper column, also explained below.


When you count cells with "OR logic", you need to be careful not to double count. For example, if you are counting cells that contain "abc" or "def", you can't just add together two COUNTIF functions, because you may double count cells that contain both "abc" and "def".

Single cell solution

For a single formula, you can use SUMPRODUCT with ISNUMBER + FIND. The formula in F5 is:

=SUMPRODUCT(--((ISNUMBER(FIND("abc",B5:B11)) +  ISNUMBER(FIND("def",B5:B11)))>0))

This formula is based on the formula explained here that locates text inside of a cell:


When given a range of cells, this snippet will return an array of TRUE/FALSE values, one value for each cell the range. Since we are using this twice (once for "abc" and once for "def"), we'll get two arrays.

Next, we add these arrays together (with +), which creates a new single array of numbers. Each number in this array is the result of adding the TRUE and FALSE values in the original two arrays together. In the example shown, the resulting array looks like this:


We need to add these numbers up, but we don't want to double count. So we need to make sure any value greater than zero is just counted once. To do that, we force all values to TRUE or FALSE with ">0", then force to 1/0 with the double-negative (--).

Finally, SUMPRODUCT returns the sum of all values in the  array.

Helper column solution

With a helper column to check each cell individually, the problem is less complex. We can use COUNTIF with two values (provided as an "array constant"). The formula in C5 is:


Check if cell contains either x or y with COUNTIF

COUNTIF will return an array that contains two items: a count for "abc" and a count for "def". To prevent double counting, we add the items up and then force the result to TRUE/FALSE with ">0". Finally, we convert the TRUE/FALSE values to 1's and 0's with a double negative (--).

The final result is either 1 or 0 for each cell. To get a total for all cells in the range, simply sum the helper column.

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.