Skip to main content

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.
doc count equal to either x or y 1

Count cells equal to x or y by the COUNTIF function

Generic formula:

COUNTIF(range,value1)+ COUNTIF(range,value2)+…

Arguments

  • Range: Required, the cells you want to count that match to criteria from.
  • Value1, value2: Required, the criteria that the cells need to match to while counting.

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)
doc count equal to either x or y 2

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

  • Range: Required, the cells you want to count that match to criteria from.
  • Criteria1, criteria2: Required, the criteria that the cells need to match to while counting.

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.
doc count equal to either x or y 3

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

  • Range: Required, the cells you want to count that match to criteria from.
  • Things: Required, the name of a range that including all criteria you count cells based on.

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:
doc count equal to either x or y 4

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:
doc count equal to either x or y 5

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

doc sampleClick to download sample file


Relative Formulas


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.
Ribbon of Excel (with Kutools for Excel installed)

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.
Screen Shot of Excel (with Office Tab installed)
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations