Counting From Two Ranges

PShingadia

New Member
Joined
Aug 5, 2015
Messages
47
Hi

Just wondered if anyone can help with a formula to count out items in a list based on a count in another range. So in the example below the little box says how many to count in total and from the list I wish to count out that many and it more to show as zero.

[TABLE="width: 506"]
<colgroup><col span="5"><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD]Count[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]Total Items to Count[/TD]
[/TR]
[TR]
[TD]Fox[/TD]
[TD] 1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Fox[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]Fox[/TD]
[TD] 2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Rabbit[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]Rabbit[/TD]
[TD] 1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Sqirrel[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]Rabbit[/TD]
[TD] 2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Rabbit[/TD]
[TD] - [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Rabbit[/TD]
[TD] - [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Fox[/TD]
[TD] 3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Fox[/TD]
[TD] 4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Rabbit[/TD]
[TD] - [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Squirrel[/TD]
[TD] 1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Rabbit[/TD]
[TD] - [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Squirrel[/TD]
[TD] 2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Fox[/TD]
[TD] 5[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Squirrel[/TD]
[TD] 3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Squirrel[/TD]
[TD] - [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Squirrel[/TD]
[TD] - [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Squirrel[/TD]
[TD] - [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Fox[/TD]
[TD] - [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Fox[/TD]
[TD] - [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Fox[/TD]
[TD] - [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]


So box says 5 foxes and result I want is formula that marks out 5 foxes 1 to 5 and any more show as zero. Marked out 2 rabbits and rest shown as zero, etc. I have the formula = IF(AND(COUNTIF($C$3:$C3,$H$3)<=$I$3, $C3=$H$3), COUNTIF($C$3:$C3,$H$3), 0) but don't know how to apply over the range.

Thanks for your help.
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Somthing like this should work ok.

=IF(COUNTIF($A$2:A2,A2)>VLOOKUP(A2,$F$2:$G$4,2,0),0,COUNTIF($A$2:A2,A2))

MAke sure you spell your words correctly or it will fail!
 
Upvote 0
[TABLE="class: grid"]
<tbody>[TR]
[TD][/TD]
[TD]
A
[/TD]
[TD]
B
[/TD]
[TD]
C
[/TD]
[TD]
D
[/TD]
[TD]
E
[/TD]
[TD]
F
[/TD]
[TD]
G
[/TD]
[TD]
H
[/TD]
[/TR]
[TR]
[TD]
1
[/TD]
[TD]Fox[/TD]
[TD]
1​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Fox[/TD]
[TD]
5​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
2
[/TD]
[TD]Fox[/TD]
[TD]
2​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Rabbit[/TD]
[TD]
2​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
3
[/TD]
[TD]Rabbit[/TD]
[TD]
1​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Squirrel[/TD]
[TD]
3​
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
4
[/TD]
[TD]Rabbit[/TD]
[TD]
2​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
5
[/TD]
[TD]Rabbit[/TD]
[TD]-[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
6
[/TD]
[TD]Rabbit[/TD]
[TD]-[/TD]
[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​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
14
[/TD]
[TD]Squirrel[/TD]
[TD]
3​
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
15
[/TD]
[TD]Squirrel[/TD]
[TD]-[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
16
[/TD]
[TD]Squirrel[/TD]
[TD]-[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
17
[/TD]
[TD]Squirrel[/TD]
[TD]-[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
18
[/TD]
[TD]Fox[/TD]
[TD]-[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
19
[/TD]
[TD]Fox[/TD]
[TD]-[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]
20
[/TD]
[TD]Fox[/TD]
[TD]-[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

G2=
COUNTIFS($A$1:$A$20,$F1,$B$1:$B$20,"<>"&$B$5) copy down

Thank you very much - cleaner solution!
 
Upvote 0
Cleaner solution? Did you try it? It isn't a solution to your problem.
 
Upvote 0
Steve: you are right! Looked cleaner when I first saw but it was wrong and gone back to your solution and using : =IF(COUNTIF($A$2:A2,A2)>VLOOKUP(A2,$F$2:$G$4,2,0),0,COUNTIF($A$2:A2,A2)) which works

Is it possible to make an adjustment to this so that the items it counts are selected randomly? At the moment the count starts from the first item it finds and all those at the end are zero. Could it select these randomly but total for each comes to the quantity required in the little box?

Thanks for your help so far
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,198
Members
453,022
Latest member
RobertV1609

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