Dynamic formula - Find the first negative value and turn the subsequent rows 0

Cubist

Well-known Member
Joined
Oct 5, 2023
Messages
1,819
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Given a dynamic array of numerical values.
The array always starts with positive values. Once it turns negative, the remaining rows will be negative.
I want to turn the first negative value positive and the subsequent negative values into 0.
I'm looking for a dynamic array solution that can handle both cases below. TIA

Book1
ABCDEF
1Case 1ExpectedCase 2Expected
2151500
3353500
4151500
5262600
6111100
7181800
8-454500
9-29000
10-6000
11-6000
12-27000
13-25000
14-27000
15-19000
16-6000
17
Sheet5
Cell Formulas
RangeFormula
A2:A16A2={15;35;15;26;11;18;-45;-29;-6;-6;-27;-25;-27;-19;-6}
B2:B7B2=A2:A7
D2:D16D2=SEQUENCE(15,1,0,0)
Dynamic array formulas.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
The array always starts with positive values.
That doesn't appear to be the situation with Case 2.

Anyway, try this

24 03 25.xlsm
ABCDE
1Case 1ExpectedCase 2Expected
2151500
3353500
4151500
5262600
6111100
7181800
8-454500
9-29000
10-6000
11-6000
12-27000
13-25000
14-27000
15-19000
16-6000
Cubist
Cell Formulas
RangeFormula
A2:A16A2={15;35;15;26;11;18;-45;-29;-6;-6;-27;-25;-27;-19;-6}
B2:B16,E2:E16B2=LET(r,A2#,IF(r>=0,r,IF(OFFSET(r,-1,0)>0,-r,0)))
D2:D16D2=SEQUENCE(15,1,0,0)
Dynamic array formulas.
 
Upvote 0
Looking back at this, my formula might not meet the requirements as shown in the example below. For this sample data my previous formula (col B) fails to turn the first negative into positive so amended formula given in col C.

24 03 25.xlsm
ABC
1Case 1Expected
2151515
3353535
4151515
5262626
6111111
7000
8-45045
9-2900
10-600
11-600
12-2700
13-2500
14-2700
15-1900
16-600
Cubist (2)
Cell Formulas
RangeFormula
A2:A16A2={15;35;15;26;11;0;-45;-29;-6;-6;-27;-25;-27;-19;-6}
B2:B16B2=LET(r,A2#,IF(r>=0,r,IF(OFFSET(r,-1,0)>0,-r,0)))
C2:C16C2=LET(r,A2#,IF(r>=0,r,IF(OFFSET(r,-1,0)>=0,-r,0)))
Dynamic array formulas.
 
Upvote 0
Solution
I meant to say 0 or positive values. This works. Thanks!
 
Upvote 0

Forum statistics

Threads
1,223,532
Messages
6,172,878
Members
452,486
Latest member
standw01

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