Count back or forward based on (moving) zero cell?

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
477
Office Version
  1. 365
Platform
  1. Windows
I'm struggling to create a formula that will count positive or negative numbers based off of 0.

Example: I have a column with 30 rows. If I put a zero in A10 I want A9 to show -1, A8 -2, etc. and A11 to show 1, A12 2, etc.. If I later put the zero in A15 then A14 should be -1, A16 1, and so on.

Make sense?
 
So should the row with 0 be 1?
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
In that case how about
Excel Formula:
=ROW()-MATCH(0,$A$1:$A$30,0)+(ROW()>=MATCH(0,$A$1:$A$30,0))
 
Upvote 0
In that case how about
Excel Formula:
=ROW()-MATCH(0,$A$1:$A$30,0)+(ROW()>=MATCH(0,$A$1:$A$30,0))

I changed the 0 to 1 and it works perfect. Thanks!

Excel Formula:
=ROW()-MATCH(1,$A$1:$A$30,1)+(ROW()>=MATCH(1,$A$1:$A$30,1))
 
Upvote 0
I changed the 0 to 1 and it works perfect.
I don't know if it is likely to happen, but if any new rows are subsequently added at the top of the sheet, the formula will then return incorrect results.
An alternative formula that is robust against row insertion (& is a bit shorter) is ..

20 10 01.xlsm
AB
1-9
2-8
3-7
4-6
5-5
6-4
7-3
8-2
9-1
1011
112
123
134
145
156
167
178
189
1910
2011
2112
2213
2314
2415
2516
2617
2718
2819
2920
3021
Sequence
Cell Formulas
RangeFormula
B1:B30B1=ROWS(A$1:A1)-MATCH(1,A$1:A$30)+COUNT(A$1:A1)
 
Upvote 0

Forum statistics

Threads
1,215,563
Messages
6,125,550
Members
449,237
Latest member
Chase S

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