x
Solved

USING COUNTIF WITH MULTIPLE CRITERIA

Posted on 2002-06-03
Medium Priority
945 Views
I want to be able to do a COUNTIF on 2 columns at the same time.  So in Column K, I have either a 1, 2 or 3.  In Column L, I have either a 1, 2 or 3.  I want it to count only those rows that have both a "1" in Columns K AND L.  Here's what I've tried, but these don't work.

=COUNTIF(K2:K34,"1")*AND(L2:L34,"1")   I get #VALUE

=COUNTIF(K2:K34,"1")*AND(COUNTIF(L2:L34,"1")) get error message

I've tried using the AND function, but am not sure how to use it with COUNTIF function, if I even can (?????).
0
Question by:esu4236
• 3
• 3

LVL 11

Expert Comment

ID: 7051652
Instead of CountIf try using a combination of IF() with AND() like this...

=IF(AND(K1=1,L1=1),1,"")

Then you can simply Sum the column with the If function to get the count of matching columns containing "1"
0

Author Comment

ID: 7051713
Well, I really don't want to have to add yet another column.  Isn't there another way without doing this?
0

LVL 11

Expert Comment

ID: 7051880
IMHO columns are cheap, time is expensive. Off hand I don't see how you are going to do this using just COUNTIF().

The trouble is that COUNTIF() expects to check the value of every SINGLE cell in a range but you want to compare the values of two cells, so you need to have somewhere to store the results of that comparision before you can count them.

So either you use another column for the comparison result, or else you write your own function which will take a two column rage as it's imput parameter. The function would then compare each pare of cells within it's VBA code and store the intermediate results in a variable, which would then be used to return value of the function.
0

LVL 6

Accepted Solution

bkpchs237 earned 400 total points
ID: 7051926
esu4236,

You could try an array formula, by entering the following into a cell and pressing ctrl+shift+enter to enter it as an array formula:
=SUM((K2:K34=1)*(L2:L34=1))

Hope this helps.
0

Author Comment

ID: 7052051
Thank you very much BKPCHS237 for your solution.  That worked perfect!!!!!  I knew there had to be a way to do it without adding more columns.  Thanks again - you made my day!!!!!

0

Author Comment

ID: 7052053
Thank you very much BKPCHS237 for your solution.  That worked perfect!!!!!  I knew there had to be a way to do it without adding more columns.  Thanks again - you made my day!!!!!

0

LVL 11

Expert Comment

ID: 7052179
bkpchs237 : as in infrequent user of Excel (I spend most of my days with Access) I am gratefull to you for your enlightening answer - Array functions have been something I've steered clear of before now.

0

Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.