To sum if cells contain either one text string or another (i.e. contain "cat" or "rat") you can use the SUMPRODUCT function.
When you sum cells with "OR" criteria, you need to be careful not to double count when there is a possibility that both criteria will return true. In the example shown, we want to sum values in Column C when cells in column B contain either "cat" or "rat". We can't use SUMIFs with two criteria, because SUMIFS is based on AND logic. And if we try to use two SUMIFS (i.e. SUMIFS + SUMIFS) we will double count because there are cells that contain both "cat" and "rat"
One solution is to use SUMPRODUCT with ISNUMBER + SEARCH or FIND. The formula in cell F4 is:
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 "cat" and once for "rat"), 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 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 by checking the array with ">0". This returns TRUE / FALSE:
Which we then convert to 1 / 0 using a double negative (--):
The SEARCH function ignores case. If you need a sensitive option, replace SEARCH with FIND.
To sum if cells contain both x and y (i.e. contain "cat" and "rat", in the same cell) you can use the SUMIFS function. In the example shown, the formula in F5 is: = SUMIFS ( C4:C8 , B4:B8 , "*cat*" , B4:B8 , "*rat*" ) How this...
To count cells that contain either one value or another, you an either use a helper column then tally up the count, or a more complex single cell formula. Background When you count cells with "OR" criteria, you need to be careful not to double count...
To check if a cell contains specific text, you can use the SEARCH function together with the ISNUMBER function. In the generic version, substring is the specific text you are looking for, and text represents text in the cell you are testing. In the...
To count the number of cells that contain certain text, you can use the COUNTIF function. In the generic form of the formula (above), rng is a range of cells, txt represents the text that cells should contain, and "*" is a wildcard matching any...
To count the number of cells equal to either one value OR another, you use formula that uses the COUNTIF function twice. In the example, the active cell contains this formula: = COUNTIF ( B4:B9 , "apples" ) + COUNTIF ( B4:B9 , "pears...
SUMIFS is a function to sum cells that meet multiple criteria. SUMIFS can be used to sum values when adjacent cells meet criteria based on dates, numbers, and text. SUMIFS supports logical operators (>,...
The SUMPRODUCT function multiplies ranges or arrays together and returns the sum of products. This sounds boring, but SUMPRODUCT is an incredibly versatile function that can be used to count and sum like COUNTIFS or SUMIFS, but with more...
The Excel ISNUMBER function returns TRUE when a cell contains a number, and FALSE if not. You can use ISNUMBER to check that a cell contains a numeric value, or that the result of another function is a number.
The Excel SEARCH function returns the location of one text string inside another. SEARCH returns the position of the first character of find_text inside within_text. Unlike FIND, SEARCH allows wildcards, and is not case-sensitive.
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.