How to count consecutive numbers based on the first number of the column

Mathman

Board Regular
Joined
Jan 28, 2017
Messages
152
Office Version
  1. 2016
Platform
  1. Windows
Hi


Looking for a formula to count the consecutive numbers in 1 column based on the first Number/Column.


Then if the first number in the column is Zero the result is shown as a negative number but if the first number in the column is 1 the result is shown as a positive number.


If you can help it would be greatly appreciated.


Here is an example.





Result-1-132
ABCD
10011
21111
30110
40000
50000
61011
71111
81101
91011
101111
111110
121100
130000
141010
151101
161011
171111
181111
191111
201111
THX

<tbody>
</tbody>

<tbody>
</tbody>






 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I thought I had responded to this same query elsewhere, but I can't find it. Please explain your requirements in more detail.
 
Upvote 0
You did, hope this helps.

Let's look at column A as each Column will have it's own result. The starting point is to look at row 1 first. This will determine if the result will be expressed as a positive number or a negative number. Zero is negative and 1 is positive. In column A the first number is negative making the result expressed as a negative number, we then look at row 2. Row 2 is a 1. This means that based on the first row the Zero was followed by a 1 and the formula end as simply one consecutive negative number giving the result of -1

If you look at column C the first row number is 1 making the result a positive number of 1. you then look at row 2 and you still have a 1 bringing the total to 2. Then row 3 has another 1 with a new total of 3 but then when you look at row 4 you have a zero so the total consecutive numbers for this column would be 3 as the zero in row 4 stops the consecutive number count.




I use this to track consecutive days up or down for stocks. You can think of the rows(1 threw 20) as days. 1 would be today, 2 yesterday and so on. What I want to know is based on today how many consecutive days were up (positive number) or down (negative numbers)


I hope this makes sense. Thank you for the reply.
 
Upvote 0
Where did I respond? Was it a different forum? If so you need to provide a link to that thread.

Why is the result in B not -2?
 
Last edited:
Upvote 0
you simple asked me to clarify but you didn't suggest a formulae.
 
Upvote 0
For column B the result is -1 because the formulae is based on the first row, B1 is a zero making the result a negative number, then in row to you have a 1 being a positive number. Since you have only one zero followed by a 1 the calculation must end and all other rows are not needed giving you a result of only 1 consecutive Zero (result -1)

How to count consecutive numbers based on the first number of the column
 
Upvote 0
OK - so if the first value is a zero, we record -1, so there can be no other negative number result - is this correct?
 
Upvote 0
Try this in A1 copied across:

=IF(A4=0,-1,MATCH(0,A$4:A$23,0)-1)


Excel 2016 (Windows) 32 bit
ABCD
1-1-132
2ABCD
3
40011
51111
60110
70000
80000
91011
101111
111101
121011
131111
141110
151100
160000
171010
181101
191011
201111
211111
221111
231111
Sheet1
Cell Formulas
RangeFormula
A1=IF(A4=0,-1,MATCH(0,A$4:A$23,0)-1)
B1=IF(B4=0,-1,MATCH(0,B$4:B$23,0)-1)
C1=IF(C4=0,-1,MATCH(0,C$4:C$23,0)-1)
D1=IF(D4=0,-1,MATCH(0,D$4:D$23,0)-1)
 
Last edited:
Upvote 0
thx Ali but it doesn't quite fit. Take a look at this and tell me what you think. I listed several rows with your formulae result and the correct results.


TRUEFALSETRUEFALSEFALSEFALSEFALSETRUETRUETRUETRUEFALSEFALSEFALSETRUETRUEFALSETRUETRUETRUE#N/A
Your Formulae-1-1-1662-1-1-1-1-1666-1-1-1-1-1-1#N/A
Corect Result-1-2-1331-2-1-1-1-1333-1-1-2-1-1-120
ABCDEFGHIJKLMNOPQRSTU
1000111000001110000001
2101110011111111101111
3111110111111111111111
4111000000110000001111
5000000000100000000011
6000000011000000000111
7101111111110111111111
8111111111111111111111
9110111100001111111111
10101110000001111111111
11111110101111111111111
12111000000111111111111
13110000000001111111111
14000000000011111111111
15100001111111111111111
16110111111111111111111
17100111111111111111111
18111111111111111111111
19111111111111111111111
20111111111111111111111

<colgroup><col width="104" style="width: 78pt;"><col width="47" span="21" style="width: 35pt;"></colgroup><tbody>
</tbody>
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,260
Members
449,075
Latest member
staticfluids

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