Complex countifs formula

anglais428

Well-known Member
Joined
Nov 23, 2009
Messages
634
Office Version
  1. 2016
Platform
  1. Windows
I am providing a sample table below:

A
B
A
A
B

<tbody>
</tbody>

I can do a Countif to get the number of A's or B's. Or something like =SUM(COUNTIF($A$2:$A$7,{"A","B"})) to get the number of As and Bs.
I would like to refer to the part {"A","B"} as a cell reference, rather than have to manually type this.

Note, this is a condensed version for illustration only (so sumproduct would not be the best result for me).

Thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi, like this maybe:


Excel 2013/2016
ABCDE
1AA5
2BB
3A
4A
5B
Saturday 2 (2)
Cell Formulas
RangeFormula
E1=SUMPRODUCT(COUNTIF(A1:A5,C1:C2))
 
Upvote 0
Thanks FormR,
I am trying to avoid this type of formula (if possible) as there are multiple items inside one cell (e.g. {"milk","juice","tea","coffee"}) and it would be preferable (if possible) to keep them listed like this in the one cell rather than splitting them into a single cell each.
 
Upvote 0
Hi, it is a little more complex but if you can set it up by not including the {} and "" characters as below then you can try:


Excel 2013/2016
ABCD
1AA,B8
2B
3A
4A
5B
6C
7A
8A
9B
10C
Sheet1
Cell Formulas
RangeFormula
D1=SUMPRODUCT(COUNTIF($A$1:$A$10,TRIM(MID(SUBSTITUTE(C1,",",REPT(" ",99)),ROW(INDEX(A:A,1):INDEX(A:A,LEN(C1)-LEN(SUBSTITUTE(C1,",",""))+1))*99-98,99))))
 
Last edited:
Upvote 0
Thanks, this is awesome. I can certainly work with this!
 
Upvote 0
Apologies, is it possible to take this one step further.

E.g.

A1A,B6
B11
C1
A1
A1
A1
B1
B2
B2
C1

<tbody>
</tbody>

So the answer would be 6 based on finding A and B in the first column and where "1" is beside each A or B in the second column.

Thanks
 
Upvote 0
if you change your file in this way

A
B
C
D
E
1
A
1​
a
6​
2
B
1​
b
3
C
1​
1​
4
A
1​
5
A
1​
6
A
1​
7
B
1​
8
B
2​
9
B
2​
10
C1

<tbody>
</tbody>



e1=
SUMPRODUCT(COUNTIFS(A1:A9,D1:D2,B1:B9,B1))
 
Upvote 0
is it possible to take this one step further.

Hi, not sure if you've already figured it out, but here is one way:


Excel 2013/2016
ABCDE
1A1A,B6
2B11
3C1
4A1
5A1
6A1
7B1
8B2
9B2
10C1
Sheet1
Cell Formulas
RangeFormula
E1=SUMPRODUCT(COUNTIFS($B$1:$B$10,D2,$A$1:$A$10,TRIM(MID(SUBSTITUTE(D1,",",REPT(" ",99)),ROW(INDEX(A:A,1):INDEX(A:A,LEN(D1)-LEN(SUBSTITUTE(D1,",",""))+1))*99-98,99))))
 
Upvote 0
Also, if you define List1 in the Name Manager as referring to:

={"milk","juice","tea","coffee"}

you can just have:

=SUMPRODUCT(COUNTIFS,List1))
 
Upvote 0
Thanks Aladin - I completely forgot about the named ranges - this works great.

Thanks also FormR and MARZIOTULLI, whose formulas also work.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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