Reputation: 13
Can we have a formula or a VBA code for counting number of next cells based on criteria.
For instance if we have a list
A
A
B
A
C
and we would like to count number of A's after A (the criteria), so in this case, it would be 1
Upvotes: 0
Views: 71
Reputation: 1927
The simplest possible solution that I can think for this problem is
=IF(A2<>A1,0,INDEX(MATCH(FALSE,A2:A100=A1,0),1,1)-1)
Upvotes: 0
Reputation: 12113
If you just want to know the number of times A
is followed by A
then you can use a formula like this
=COUNTIFS(A1:A5,"A",A2:A6,"A")
Assuming your data is in A1:A5
This will also allow you to find out how many times A
is followed by B
or any other combination by changing the criteria
Upvotes: 2
Reputation: 152505
Use SUMPRODUCT():
=SUMPRODUCT(($A$1:$A$5="A")*($A$2:$A$6=$A$1:$A$5))
Upvotes: 1