Solved

USING COUNTIF WITH MULTIPLE CRITERIA

Posted on 2002-06-03
7
938 Views
Last Modified: 2012-06-21
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
Comment
Question by:esu4236
  • 3
  • 3
7 Comments
 
LVL 11

Expert Comment

by:LambertHeenan
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

by:esu4236
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

by:LambertHeenan
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Accepted Solution

by:
bkpchs237 earned 100 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

by:esu4236
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

by:esu4236
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

by:LambertHeenan
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question