A
Anderson
In the range a1:a3
123
221
332
How to count the number of 2's in the range,which would be 4
123
221
332
How to count the number of 2's in the range,which would be 4
Biff said:As long as the numbers are only 3 digits:
1st pos - =SUMPRODUCT(--(--LEFT(A1:A3,1)=2))
2nd pos - =SUMPRODUCT(--(--MID(A1:A3,2,1)=2))
3rd pos - =SUMPRODUCT(--(--RIGHT(A1:A3,1)=2))
-----Original Message-----
Why assume these strings are only 3 digits?
Why use two sets of unary minuses?
1st pos - =SUMPRODUCT(--(MID(A1:A3,1,1)="2"))
2nd pos - =SUMPRODUCT(--(MID(A1:A3,2,1)="2"))
3rd pos - =SUMPRODUCT(--(MID(A1:A3,3,1)="2"))
Why use SUMPRODUCT?
1st pos - =SUMIF(A1:A3,"2*")
2nd pos - =SUMIF(A1:A3,"?2*")
3rd pos - =SUMIF(A1:A3,"??2*")
.
1st pos - =SUMIF(A1:A3,"2*")
2nd pos - =SUMIF(A1:A3,"?2*")
3rd pos - =SUMIF(A1:A3,"??2*")
Frank Kabel said:why use SUMIF
you probably meant
=COUNTIF(A1:A3,"2*")
....Anderson said:It seems there can be no empty cells in the range for this to work....