How to Count Cells That are Equal to One of Many Cells in Excel

Sometimes we want to count cells that contain value defined in other cells. In that case simple COUNTIF and COUNTIFS function will not work. We can use an combination of SUMPRODUCT and COUNTIF function of Excel to achieve that.

Generic Formula to Count One of Many Cells

=SUMPRODUCT(COUNTIF(range,criteria)

Range: the range in which you want to match the criteria.

Criteria: the reference of values that you want to count in Range.

Let’s see an example to make things clear.
Example: Count The Total of Pen and Pencils in  a List
Here I have this list in range A2:A10. In cell D2:D4 I have list of items, whose total count is required.

One way is to count each item separately using countif function and then add them up to get total count of those item. For that I will be adding a helping row. But I don’t want to do that.

Another way is to use 2 countifs for each item and then and use SUM function or addition operator. But if you have hundreds of items to get count of then this method of counting will be useless.

Hence we use the above mentioned generic formula to get total count of listed item.

Apply above generic formula here to get total count of each value.

=SUMPRODUCT(COUNTIF(A2:A10,D2:D4))

This returns 5. The pencil is found 4 times, Pen 1 time, and Compass is found 0 times.

How it works?

Well this is quite simple. If you just write the COUNTIF(A2:A10,D2:D4) in a cell as an array formula, it will return the count of first value in range D2:D4. But internally it is returning an array of count of each item in D2:D4. {4;1;0} this is the array it is returning in the above example.
Now we just need to sum each the values. For that we used SUMPRODUCT function of Excel. It sums up the counts and gives us the total count of each value in given range.
You must be thinking, why not use SUM function. Well you can use it, but then you will need to use it as an array formula.
So yeah guys, this how you get count of multiple items using one simple excel formula. Let me know if you have any doubts regarding this function or any other function of excel. The comments section is all yours.

Related Articles:

Count Characters in a Cell in Excel

Counting the Number of Values between Two Specified Values in a List in Microsoft Excel

Count Cells that contain specific text

Count Cells With Text

Popular Articles:

The VLOOKUP Function in Excel

COUNTIF in Excel 2016

How to Use SUMIF Function in Excel

Leave a Reply

Your email address will not be published. Required fields are marked *

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.

Visit Us On TwitterVisit Us On FacebookVisit Us On Youtube