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:


Generic formula



The SUMIFS function is based on AND logic and this behavior is automatic. We just need to supply two range/criteria pairs, both operating on the same range (B4:B11).

For both criteria (contains "rat", contains "cat") we use an asterisk, which is a wildcard that matches "one or more characters". We put an asterisk at the start and end to allow the formula to match "cat" and "rat" wherever they appear in the cell.

When both criteria return TRUE in the same row, SUMIFS sums the value in column C.

Note that SUMIFs is not case-sensitive.

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.