COUNTIF with criteria from two columns

xljruser

New Member
Joined
Feb 1, 2005
Messages
6
Hi all, longtime lurker, first time poster

I've looked all over this site, but cant seem to find my answer, which is a first. :oops: I am trying to create a COUNTIF formula, with criteria from 2 columns, A and B

Column A is a list of FRUITS, and column B is the COLOUR. I would like to use some sort of COUNT formula which will tell me how many Apples are "red"
Apples can be red, green and yellow, but I would like to know how many apples are only red.

I used =IF(AND(A4:A27="apples",B4:B27="red"),"match","no") for each line just to test it. But i would like to use a COUNTIF statement. I thought maybe could use the same approach with =COUNTIF(AND.......)but just cant seem to get it

Any help would be great,
Thanks in andvance
 

Some videos you may like

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
The COUNTIF function doesn't accept multiple criteria; you need to use the SUMPRODUCT function:
Book1
ABCD
1FruitsColor#ofredapples:3
2ApplesRed
3ApplesGreen
4ApplesRed
5ApplesRed
6ApplesYellow
7ApplesGreen
8ApplesGreen
9ApplesYellow
10ApplesYellow
Sheet1
 

xljruser

New Member
Joined
Feb 1, 2005
Messages
6
Thanks for the quick response. Works like a charm.

Now, what about if I had a Column C, an it had the price of all the fruits, and I wanted to know the total price of all apples which are red. Again, I think it would be a version of the =SUM(IF(A1:A50="APPLES",C2:C25)) This wil give me the sum of the price of apples, but can i insert another critera in there,

SUM(IF(A1:A50="Apples", B1:B50="red",C1:C50))

I know this is incorrect, but it's where i want to start. I tired to use this with the =SUMPRODUCT(--($A$1:$A$10="Apples"),--($B$1:$B$10="Red")) formula, but stuck again.
 

fairwinds

MrExcel MVP
Joined
May 15, 2003
Messages
8,638
Just add the column to sum at the end:

=SUMPRODUCT(--($A$1:$A$10="Apples"),--($B$1:$B$10="Red"),$C$1:$C$10)
 

Watch MrExcel Video

Forum statistics

Threads
1,122,959
Messages
5,599,056
Members
414,281
Latest member
Engjamal2021

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top