Count the number of times a range matches criteria

SillyCat

New Member
Joined
Jun 21, 2011
Messages
15
Hello,

I'm normally okay at muddling though working out how to do what I want in Excel but I've had no luck trying to figure this out by myself using F1 Help or looking online. But at the same time I'm sure I'm thinking about it wrong and there is a simple answer I'm overlooking :laugh:

So I'm starting off with something like this:
<table>
<tr><td></td><td>Apple</td><td>Banana</td><td>Clementine</td><td>Date</td><td></td></tr>
<tr><td></td><td>40</td><td>30</td><td>45</td><td>50</td><td></td></tr>
<tr><td></td></tr>
<tr><td>Anne</td><td>26</td><td>14</td><td>15</td><td>1</td><td></td></tr>
<tr><td>Betty</td><td>1</td><td>30</td><td>3</td><td>6</td><td></td></tr>
<tr><td>Cathy</td><td>29</td><td>28</td><td>8</td><td>46</td><td></td></tr>
<tr><td>Debbie</td><td>40</td><td>20</td><td>37</td><td>50</td><td></td></tr>
<tr><td>Etc.</td><td>2</td><td>30</td><td>45</td><td>50</td><td></td></tr>
</table>

The numbers under the fruit is the target or criteria for that fruit. I want to add a column to the end that counts how many fruits each person has hit the target for like so:
<table>
<tr><td></td><td>Apple</td><td>Banana</td><td>Clementine</td><td>Date</td><td></td></tr>
<tr><td></td><td>40</td><td>30</td><td>45</td><td>50</td><td></td></tr>
<tr><td></td></tr>
<tr><td>Anne</td><td>26</td><td>14</td><td>15</td><td>1</td><td>0</td></tr>
<tr><td>Betty</td><td>1</td><td>30</td><td>3</td><td>6</td><td>1</td></tr>
<tr><td>Cathy</td><td>29</td><td>28</td><td>8</td><td>46</td><td>4</td></tr>
<tr><td>Debbie</td><td>40</td><td>20</td><td>37</td><td>50</td><td>2</td></tr>
<tr><td>Etc.</td><td>2</td><td>30</td><td>45</td><td>50</td><td>3</td></tr>
</table>

But for the life of me I can't think how to go about it. I was thinking of using countif but I couldn't think how to make the evaluation for each cell to be relative to its position.

I'm stuck using Excel 2003 and your help is greatly appreciated, many a time I've ended up finding the answer on this site when I've needed help to get things done in Excel its been a godsend, thanks.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Oh forgot to mention, I'm looking for a way to do this using without using macros if possible. I could probably knock up the macro myself, but ideally I want avoid using any.
 
Upvote 0
Maybe something like this ?


Excel Workbook
ABCDEF
1*AppleBananaClementineDateResult
2*40304550*
3Anne26141510
4Betty130361
5Cathy29288460
6Debbie402037502
7Etc.23045503
Sheet2


Not sure though if I understood your result correctly
 
Last edited:
Upvote 0
With your sample data in A1:E8

This regular formula returns the quota count for the first person
Code:
F4: =SUMPRODUCT(--(B4:E4>=$B$2:$E$2))
Copy that formula down as far as you need

Using the sample data, the formula return:
Anne.......0
Cathy......1
Betty.......0
Debbie.....2
etc.........3

Is that something you can work with?
 
Upvote 0
Thank you snoopyhr and Ron Coderre for you help so far.

Both are close but both have problems, I've modified the data below (In bold) to highlight the two problems. snoopyhr's is matching each persons fruit count with any matching fruit value, e.g. in the case below it is counting Anne's 30 apples, I'm after it counting if they have the right number for each different fruit. I.E. 40 for Apple 30 for Banana.

Ron Coderre works but counts text as a match. Any hints on how to modify either formula to overcome these obstacles? Thanks.

Also I'm trying to understand how they work what is the -- for/do?

Thank you for you help so far guys.

<table border="1" cellspacing="0" cellpadding="0" style="font-family:Arial,Arial; font-size:10pt; background-color:#ffffff; padding-left:2pt; padding-right:2pt; "> <colgroup><col style="font-weight:bold; width:30px; " /><col style="width:64px;" /><col style="width:64px;" /><col style="width:64px;" /><col style="width:64px;" /><col style="width:64px;" /><col style="width:64px;" /></colgroup><tr style="background-color:#cacaca; text-align:center; font-weight:bold; font-size:8pt; "><td >*</td><td >A</td><td >B</td><td >C</td><td >D</td><td >E</td><td >F</td><td >G</td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >1</td><td >*</td><td >Apple</td><td >Banana</td><td >Clementine</td><td >Date</td><td >snoopyhr Result</td><td >Ron Coderre Result</td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >2</td><td >*</td><td style="text-align:right; ">40</td><td style="text-align:right; ">30</td><td style="text-align:right; ">45</td><td style="text-align:right; ">50</td><td >*</td><td >*</td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >3</td><td >Anne</td><td style="text-align:right; "><b>30</b></td><td style="text-align:right; ">14</td><td style="text-align:right; ">15</td><td style="text-align:right; ">1</td><td style="text-align:right; "><b>1</b></td><td style="text-align:right; ">0</td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >4</td><td >Betty</td><td style="text-align:right; "><b>Text</b></td><td style="text-align:right; ">30</td><td style="text-align:right; ">3</td><td style="text-align:right; ">6</td><td style="text-align:right; ">1</td><td style="text-align:right; "><b>2</b></td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >5</td><td >Cathy</td><td style="text-align:right; ">29</td><td style="text-align:right; ">28</td><td style="text-align:right; ">8</td><td style="text-align:right; ">46</td><td style="text-align:right; ">0</td><td style="text-align:right; ">0</td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >6</td><td >Debbie</td><td style="text-align:right; ">40</td><td style="text-align:right; ">20</td><td style="text-align:right; ">37</td><td style="text-align:right; ">50</td><td style="text-align:right; ">2</td><td style="text-align:right; ">2</td></tr><tr style="height:17px ;" ><td style="font-size:8pt; background-color:#cacaca; text-align:center; " >7</td><td >Etc.</td><td style="text-align:right; ">2</td><td style="text-align:right; ">30</td><td style="text-align:right; ">45</td><td style="text-align:right; ">50</td><td style="text-align:right; ">3</td><td style="text-align:right; ">3</td></tr></table>
 
Upvote 0
Thank you snoopyhr and Ron Coderre for you help so far.

Both are close but both have problems, I've modified the data below (In bold) to highlight the two problems. snoopyhr's is matching each persons fruit count with any matching fruit value, e.g. in the case below it is counting Anne's 30 apples, I'm after it counting if they have the right number for each different fruit. I.E. 40 for Apple 30 for Banana.

Ron Coderre works but counts text as a match. Any hints on how to modify either formula to overcome these obstacles? Thanks.

Also I'm trying to understand how they work what is the -- for/do?

Thank you for you help so far guys.

<TABLE style="PADDING-RIGHT: 2pt; PADDING-LEFT: 2pt; FONT-SIZE: 10pt; FONT-FAMILY: Arial,Arial; BACKGROUND-COLOR: #ffffff" cellSpacing=0 cellPadding=0 border=1><COLGROUP><COL style="FONT-WEIGHT: bold; WIDTH: 30px"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"><COL style="WIDTH: 64px"></COLGROUP><TBODY><TR style="FONT-WEIGHT: bold; FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center"><TD>*</TD><TD>A</TD><TD>B</TD><TD>C</TD><TD>D</TD><TD>E</TD><TD>F</TD><TD>G</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">1</TD><TD>*</TD><TD>Apple</TD><TD>Banana</TD><TD>Clementine</TD><TD>Date</TD><TD>snoopyhr Result</TD><TD>Ron Coderre Result</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">2</TD><TD>*</TD><TD style="TEXT-ALIGN: right">40</TD><TD style="TEXT-ALIGN: right">30</TD><TD style="TEXT-ALIGN: right">45</TD><TD style="TEXT-ALIGN: right">50</TD><TD>*</TD><TD>*</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">3</TD><TD>Anne</TD><TD style="TEXT-ALIGN: right">30</TD><TD style="TEXT-ALIGN: right">14</TD><TD style="TEXT-ALIGN: right">15</TD><TD style="TEXT-ALIGN: right">1</TD><TD style="TEXT-ALIGN: right">1</TD><TD style="TEXT-ALIGN: right">0</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">4</TD><TD>Betty</TD><TD style="TEXT-ALIGN: right">Text</TD><TD style="TEXT-ALIGN: right">30</TD><TD style="TEXT-ALIGN: right">3</TD><TD style="TEXT-ALIGN: right">6</TD><TD style="TEXT-ALIGN: right">1</TD><TD style="TEXT-ALIGN: right">2</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">5</TD><TD>Cathy</TD><TD style="TEXT-ALIGN: right">29</TD><TD style="TEXT-ALIGN: right">28</TD><TD style="TEXT-ALIGN: right">8</TD><TD style="TEXT-ALIGN: right">46</TD><TD style="TEXT-ALIGN: right">0</TD><TD style="TEXT-ALIGN: right">0</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">6</TD><TD>Debbie</TD><TD style="TEXT-ALIGN: right">40</TD><TD style="TEXT-ALIGN: right">20</TD><TD style="TEXT-ALIGN: right">37</TD><TD style="TEXT-ALIGN: right">50</TD><TD style="TEXT-ALIGN: right">2</TD><TD style="TEXT-ALIGN: right">2</TD></TR><TR style="HEIGHT: 17px"><TD style="FONT-SIZE: 8pt; BACKGROUND-COLOR: #cacaca; TEXT-ALIGN: center">7</TD><TD>Etc.</TD><TD style="TEXT-ALIGN: right">2</TD><TD style="TEXT-ALIGN: right">30</TD><TD style="TEXT-ALIGN: right">45</TD><TD style="TEXT-ALIGN: right">50</TD><TD style="TEXT-ALIGN: right">3</TD><TD style="TEXT-ALIGN: right">3</TD></TR></TBODY></TABLE>
Try this modified version of Ron's formula:

=SUMPRODUCT(--(ISNUMBER(B4:E4)),--(B4:E4>=$B$2:$E$2))

See these:

http://xldynamic.com/source/xld.SUMPRODUCT.html

http://mcgimpsey.com/excel/formulae/doubleneg.html
 
Upvote 0
Soooo...You're saying that, in the fruit count cells, text is a valid entry?
If no, then Data Validation could be helpful to prevent that situation.
 
Upvote 0
Thank you T. Valko and Rod Coderre, that modified formula is working great!
Now for me to sit down and get me head round how it works.
 
Upvote 0
Thank you T. Valko and Rod Coderre, that modified formula is working great!
Now for me to sit down and get me head round how it works.
Ron did the "heavy lifting". I just happened to pass by while he was on break! :)

Thanks for the feedback! :cool:
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,854
Members
452,948
Latest member
UsmanAli786

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