counting cells between specific values

cherokee

Board Regular
Joined
Apr 16, 2012
Messages
93
If I have a column of numbers in which #1 may appear numerous times, I need to count the number of cells between each appearance of #1
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I'm not one of the site experts... but I had an idea that might work for you using Match

If you have your column of numbers in Column A, enter the formula =MATCH(1,A2:A19,0)-1 in Column B and copy to the end of your list.

If you look at the results in Column B you will see that each value of 1 in Column A has a result of 0 in Column B. The value immediately below the 0 in Column B is the number of cells between two instances of 1's in Column A. So I changed the MATCH formula into an IF statement.....

=IF((MATCH(1,A1:A18,0)-1)=0,B2,"")

I don't know if there is a way to turn this around so your count total is at the bottom of each group. Hope this gives you some ideas at least.
 
Upvote 0
I appreciate your reply. Here is an example of what I am trying to accomplish.


<tbody>
Example 1
Example 2
A
B
C
A
B
C
ideal
ideal
Formula
Formula
Formula
Formula
Data
Column
Column
Data
Column
Column
1
1
0
0
1
4
3
2
4
4
2
6
5
3
10
4
3
3
2
4
3
1
4
1
3
0
5
6
2
5
9
6
1
4
6
7
7
0
7
5
8
9
8
15
9
3
9
1
5
10
1
4
10
3
11
6
11
20
12
1
1
12
1
2
13
4
13
1
0
14
12
14
3
15
1
2
15
7

<tbody>
</tbody>
</tbody>
 
Last edited:
Upvote 0
Example 1
Example 2
A
B
C
A
B
C
ideal
ideal
Formula
Formula
Formula
Formula
Data
Column
Column
Data
Column
Column
1
1
0
0
1
4
3
2
4
4
2
6
5
3
10
4
3
3
2
4
3
1
4
1
3
0
5
6
2
5
9
6
1
4
6
7
7
0
7
5
8
9
8
15
9
3
9
1
5
10
1
4
10
3
11
6
11
20
12
1
1
12
1
2
13
4
13
1
0
14
12
14
3
15
1
2
15
7

<tbody>
</tbody>
 
Upvote 0
This recognizes each "1" and places a zero across from each in column B but does not count the number of events between each 1
Thanks
 
Upvote 0

Excel 2012
AB
1DataFormula
22 
34
410
513
66
711
80
911
1010
1110
126
1311
144
1512
1612
xl5galry.xls
Cell Formulas
RangeFormula
B2=IF(A2=1,IF(A2=1,COUNTIF($A$2:A2,"<>"&1),"")-SUM($B$1:B1),"")
 
Last edited:
Upvote 0
Words maybe powerful, but I cannot find any strong enough to express my thanks for this wonderful formula. It will save me many hours.

Thank you very much
 
Upvote 0

Forum statistics

Threads
1,213,543
Messages
6,114,243
Members
448,555
Latest member
RobertJones1986

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