COUNTIF with two arguements?

Mr. Walnuts

Board Regular
Joined
Aug 8, 2005
Messages
176
Ok in the sheet below, I am trying to use a COUNTIF function with two arguements. It doesn't seem to be working though. Is there a better way to do it? What I need is this... for example, in cell C14, I need a count of how many married male persons there are in this database at the top. In this instance, the result should be 3. The same thing applies to the rest of the blocks. you get the point I assume. If someone could clue me in to the right direction, I'd love you forever. By the way, this is just an example. the real deal is on a much larger scale with more important information.
Book1
ABCD
1NameGenderMaritalstatusShoeSize
2JosephMMarried8
3ThomasMSingle8
4JamesMSingle8
5GaryMMarried9
6JackieFMarried10
7HermanMMarried8
8CarmenFSingle9
9JessicaFMarried7
10
11
12
13MarriedSingle
14Male
15Female
16
17Shoesize
188
199
Sheet1
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi

=SUMPRODUCT(--($B$2:$B$9="M"),--($C$2:$C$9="Married"))

The criteria (ie "M" and "Married") can be cell references holding these values.

Richard
 
Upvote 0
Out of curiosity... what is the "--" for in the formula? I understand the principle behind the formula, I just dont understand why it doesn't work without the dashes.

thank you by the way
 
Upvote 0
This works as well:


=SUMPRODUCT(($B$2:$B$9="M")*($C$2:$C$9="Married"))
 
Upvote 0
The double negative sign basically forces Excel to convert the array of True/Falses to 1s and 0s. Equally, +0 or *1 could be used:

=SUMPRODUCT(($B$2:$B$9="M")+0,($C$2:$C$9="Married")+0)

=SUMPRODUCT(($B$2:$B$9="M")*1,($C$2:$C$9="Married")*1)

This works on the basis of:

True*1
True+0
--True

all equal 1 and

False*1
False+0
--False

all equal 0.

Hope this helps!

Richard
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,922
Members
449,094
Latest member
teemeren

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
Back
Top