Quick, clean, and to the point

Count cells equal to either x or y

Excel formula: Count cells equal to either x or y
Generic formula 
=COUNTIF(rng,value1) + COUNTIF(rng,value2)

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:


How this formula works

COUNTIF counts the number of cells in a range that match the supplied criteria. In this case, the criteria for the first COUNTIF is "apples" and the criteria for the second COUNTIF is "pears". The first COUNTIF returns the count of cells in B4:B9 equal to "apples". The second COUNTIF returns the count of cells in B4:B9 equal to "pears". These two counts are added together and the sum is returned as the result of the formula.

Note that text values in the criteria for COUNTIF need to be enclosed in quotes (""). Also note that COUNTIF is not not case sensitive. In the example, the words "apples" and "pears" in any combination of upper and lower case letters will be counted.

If you are counting cells that contain a numeric value, there is no need to add quotes around the numbers. For example, if in the above example you wanted to count cells that contain zero or 1, the formula is:

=COUNTIF(rng,0) + COUNTIF(rng,1)

 If you need to count cells that contain either X or Y (instead of equal to X or Y) see: count cells that contain

Dave Bruns

Excel Formula Training

Formulas are the key to getting work done in Excel. In this step-by-step 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. Start building valuable skills with Excel formulas today. Learn more.

You are an angel. I have been forever frustrated when searching for help and finding no one gets what you get...teach the basic principle first!! Thank you, Thank you! - Christine
Excel foundational video course
Excel Pivot Table video training course
Excel formulas and functions video training course
Excel Shortcuts Video Course
Excel Charts video training course