Excel formula: Count cells equal to either x or y
If you want to count cells as long as that meet at least one of given conditions (OR logic) in Excel, i.e. count cells equal to either x or y, you can use several COUNTIF formulas or combine the COUNTIF formula and SUM formula to handle this job.
Count cells equal to x or y by the COUNTIF function
Generic formula:
COUNTIF(range,value1)+ COUNTIF(range,value2)+… |
Arguments
|
Example:
Count the number of cells which are equal to “James Band” or “Steven White” in a name list of cells. Using below formulas
=COUNTIF(B3:B8,E2)+COUNTIF(B3:B8,E3) |
Or
=COUNTIF(B3:B8,"James Band")+COUNTIF(B3:B8,"Steven White") |
In above formulas, the B3:B8 is the range of cells that you want to count cells from, “James Band” and “Steven White” are the criteria you want the cells equal to.
The press Enter key to get the counted result: 4 (Cells equal to James Band or Steven White)
Count cells equal to x or y by the COUNTIF function and the SUM function together
Also, you can combine the COUNTIF and the SUM functions to count cells equal to x or y.
Generic formula:
SUM(COUNTIF(range,{criteria1,criteria2,criteria3…})) |
Arguments
|
Example:
Count the cells that are equal to Milk, Cookie or Juice in the Food list. Using this formula:
=SUM(COUNTIF(B3:B8,{"Milk","Cookie","Juice"})) |
The press Enter key to get the counted result.
Count cells equal to x or y by the COUNTIF function and the SUMPRODUCT function together
If you want the formula is shorter, you can try to use the COUNTIF function and the SUMPRODUCT function together.
Generic formula:
SUMPRODUCT(COUNTIF(range,things)) |
Arguments
|
Example:
Count the cells that equal to one value of 12, 11, or 10 from the Record list. Before you are using the formula, you need to define the criteria cells as a named range. Select the cells contains the criteria, then type a name into the Name box, then press Enter key. See screenshot:
Then using this formula:
=SUMPRODUCT(COUNTIF(B3:B8,things)) |
In the formula, B3:B8 is the range that you want to count cells from, things is the defined named range containing all criteria cells.
The press Enter key to get the counted result as below screenshot shown:
Remarks
- Above formulas count cells without case sensitive.
- If the criteria is a number value, directly type it without double quotation marks, such as COUNTIF(B1:B5,1)+COUNTIF(B1:B5,0), or =SUM(COUNTIF(B1:B5,{1,2,0})).
Sample File
Relative Formulas
- Count cells equal to
With the COUNTIF function, you can count cells that equal to or not contain a specified value. - Count cells that not equal to
In some times, you may want to count the number of cells that not equal to a given value by using the COUNTIF function. - Count cells equal to x and y
Here this article introduce the formula to count cells that at the meanwhile match two criteria. - Count cells greater than or less than
This article talks about how to use the COUNTIF function to count the number of cell that greater than or less than a number
The Best Office Productivity Tools
Kutools for Excel - Helps You To Stand Out From Crowd
Would you like to complete your daily work quickly and perfectly? Kutools for Excel brings 300 powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) and save 80% time for you.
- Designed for 1500 work scenarios, helps you solve 80% Excel problems.
- Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands.
- Become an Excel expert in 3 minutes. No longer need to remember any painful formulas and VBA codes.
- 30-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years.

Office Tab - Enable Tabbed Reading and Editing in Microsoft Office (include Excel)
- One second to switch between dozens of open documents!
- Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
- Increases your productivity by 50% when viewing and editing multiple documents.
- Brings Efficient Tabs to Office (include Excel), Just Like Chrome, Firefox, And New Internet Explorer.
