Formula to count distinct values in specified rows

Benlafleche

New Member
Joined
Aug 2, 2012
Messages
3
Dear helpers,

I have an interesting challenge for you!

I the table below:
A
1,2,3,4,5,6,7,8,9,10,11,12
B
2,3,4
C
1,6,12
A
2,6,7
A
1,2,3
C
8,9,5
B
10,2,5,6
A
1,2,3
C
3,4,5
A
6,7,7

<tbody>
</tbody>


I would like to count how many time 1 occurs in the 2nd column only in the rows where the value in the first column is A.

I would like to do this with a formula. No VBA, it's mean to be inserted in an excel tool to be used by excel newbies... Any ideas? I am stuck on this...

Using Vista and Excel 2007...

Thank you very much in advance!

Ben
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
try this

Excel 2003
ABC
1A1,2,3,4,5,6,7,8,9,10,11,121
2B2,3,40
3C1,6,120
4A2,6,70
5A1,2,31
6C8,9,50
7B10,2,5,60
8A1,2,31
9C3,4,50
10A6,7,70
Sheet2
Cell Formulas
RangeFormula
C1=IF(AND(A1="A",ISNUMBER(FIND("|",SUBSTITUTE(B1,"1,","|")))),1,0)


copy the formula down in column c
 
Upvote 0
try this
Excel 2003
ABC
1A1,2,3,4,5,6,7,8,9,10,11,121
2B2,3,40
3C1,6,120
4A2,6,70
5A1,2,31
6C8,9,50
7B10,2,5,60
8A1,2,31
9C3,4,50
10A6,7,70

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet2

Worksheet Formulas
CellFormula
C1=IF(AND(A1="A",ISNUMBER(FIND("|",SUBSTITUTE(B1,"1,","|")))),1,0)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



copy the formula down in column c

Thanks for this! However, that's not exactly what I am looking for. My need is quite specific. I would like to have a formula that counts directly the number of "1" in the 2nd column for each row with the value "A" in the first column.

Your solution pushes me to create a third column but I can't modify this sheet...

Any other idea?

Thanks again,

Ben
 
Upvote 0
try this
Worksheet Formulas
CellFormula
C1=IF(AND(A1="A",ISNUMBER(FIND("|",SUBSTITUTE(B1,"1,","|")))),1,0)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>

That doesn't work because it will find the 1s in 10, 11 or 12
 
Upvote 0
try this slight modification.

=IF(AND(A1="A",ISNUMBER(FIND("|",SUBSTITUTE("," & B1 & ",",",1,","|")))),1,0)

<tbody>
</tbody>

<tbody>
</tbody>


This wraps the numbers between 2 commas. So for the substitute "1" becomes ",1," "1,2,3,4,5" is ",1,2,3,4,5," "0,2,3,4,10,11,12" is ",0,2,3,4,10,11,12," The first 2 will respond that there is a 1 and the last will not.
 
Upvote 0
try this slight modification.

=IF(AND(A1="A",ISNUMBER(FIND("|",SUBSTITUTE("," & B1 & ",",",1,","|")))),1,0)

<TBODY>
</TBODY>

<TBODY>
</TBODY>


This wraps the numbers between 2 commas. So for the substitute "1" becomes ",1," "1,2,3,4,5" is ",1,2,3,4,5," "0,2,3,4,10,11,12" is ",0,2,3,4,10,11,12," The first 2 will respond that there is a 1 and the last will not.

par60056 - the OP doesn't want a helper column, so our suggestions doesn't work. But nice fix
 
Upvote 0
Maybe

=SUMPRODUCT(--($A$1:$A$10="A"),--(ISNUMBER(SEARCH(","&1&",",","&SUBSTITUTE($B$1:$B$10," ","")&","))))

M.
 
Upvote 0
Maybe

=SUMPRODUCT(--($A$1:$A$10="A"),--(ISNUMBER(SEARCH(","&1&",",","&SUBSTITUTE($B$1:$B$10," ","")&","))))

M.

Mr Marcelo Branco, Thank you!

This is EXACTLY what I was looking for!

I was trying without getting my way.. you did it. Thanks again. You deserve a gold medal! ;)

Thanks also to the others who tried..

Ben
 
Last edited:
Upvote 0
Mr Marcelo Branco, Thank you!

This is EXACTLY what I was looking for!

I was trying without getting my way.. you did it. Thanks again. You deserve a gold medal! ;)

Thanks also to the others who tried..

Ben

Ben,

You are very welcome and thanks for your kind words!

M.
 
Upvote 0
I thouhgt that the request was to count all 1 per cell?

Excel 2010
ABC
1
2A1,2,3,4,5,6,7,8,9,10,11,128
3B2,3,4
4C1,6,12
5A2,6,7,1,1
6A1,2,3,1
7C8,9,5
8B10,2,5,6
9A1,2,3,1
10C3,4,5
11A6,7,7,1

<tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
C2=SUMPRODUCT(--(A2:A11="A"),--(LEN(SUBSTITUTE(B2:B11,",",",,"))+2-LEN(SUBSTITUTE(","&SUBSTITUTE(B2:B11,",",",,")&",",",1,",",,"))))

<tbody>
</tbody>

<tbody>
</tbody>
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,795
Members
451,589
Latest member
Harold14

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