Excel formula/function to subtract until 0

agrych

New Member
Joined
Jul 24, 2019
Messages
4
ABCDEAAABAC
1Invoices
2YearRemainingTaskFundingInvoiceTaskFundAmount
320173014.0397M0
520156460.7198L660.7198L660.71
72018580.2899F0100A5600.74
1020196956.3999F0
1120175510.74100A5510.74
1320188737.52100A90
1420195000.00100A0
15

<tbody>
</tbody>
From visible rows, I need to subtract the Invoice amount $5600.74 from the remaining funds for Task 100 Fund A until invoice is zero - recording the amount of the invoice used under the invoice column. Notice some rows are hidden as this is a filtered table.

Having a hard time writing a formula for cells in column E to handle subtracting the invoice amount until it has all been applied to the remaining funds (oldest year first). Perhaps a VBA function could handle this?

Any suggestions would be greatly appreciated.

<tbody>
</tbody>
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Welcome to the forums.

Why are there hidden rows? Can you show them for example's sake?
 
Upvote 0
The hidden rows have a remaining value of 0 in column B
For example:
A B C D E
Row 4: 2014 0 98 L6 0
Row 6: 2018 0 99 F 0
Row 12: 2017 0 100 A 0
 
Upvote 0
Enter with Ctrl+Shift+Enter in Cell E3:
Code:
=IF($B3=0,0,IF(INDEX($AE$3:$AE$4,MATCH($C3&$D3,$AC$3:$AC$4&$AD$3:$AD$4,0))-SUMIFS($E$2:$E2,$D$2:$D2,$D3)=0,0,MIN($B3,INDEX($AE$3:$AE$4,MATCH($C3&$D3,$AC$3:$AC$4&$AD$3:$AD$4,0))-SUMIFS($E$2:$E2,$D$2:$D2,$D3))))

Will this work for you? The errors that appear are due to the Task/Funding classes not within the Task/Fund range in columns AC/AD, so you'd either need to 1) add them, and then alter the formula, 2) ignore the errors, or 3) wrap the formula within a IFERROR function.

Reach out with any questions.
 
Upvote 0
Thank you! I had to modify it a bit to get it to work for me.
The following works as desired.

=IFERROR(IF($B3=0,0,IF(INDEX($AC$3:$AC$14,MATCH($C3&$D3,$AA$3:$AA$14&$AB$3:$AB$14,0))-SUMIFS($E$2:$E2,$C$2:$C2,$C3,$D$2:$D2,$D3)=0,0,MIN($B3,INDEX($AC$3:$AC$14,MATCH($C3&$D3,$AA$3:$AA$14&$AB$3:$AB$14,0))-SUMIFS($E$2:$E2,$D$2:$D2,$D3)))),0)
 
Upvote 0
Sorry, this is the correct formula that worked for me:
=IFERROR(IF($B5=0,0,IF(INDEX($AC$3:$AC$14,MATCH($C5&$D5,$AA$3:$AA$14&$AB$3:$AB$14,0))-SUMIFS($E$2:$E4,$C$2:$C4,$C5,$D$2:$D4,$D5)=0,0,MIN($B5,INDEX($AC$3:$AC$14,MATCH($C5&$D5,$AA$3:$AA$14&$AB$3:$AB$14,0))-SUMIFS($E$2:$E4,$C$2:$C4,$C5,$D$2:$D4,$D5)))),0)
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,901
Members
449,097
Latest member
dbomb1414

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