简体   繁体   English

Excel公式,用于从另一个单元格减去到零

[英]Excel formula for subtracting down to zero then from another cell

I have been trying to create a formula for about an hour now and have gotten nowhere so I am looking for some help. 我一直在尝试创建一个公式约一个小时,但是却一无所获,因此我正在寻求帮助。 I am trying to create a formula that when an expense is above what was budgeted for it, rather than have the budget go negative, it is reduced to zero and the remaining balance if pulled from savings. 我正在尝试创建一个公式,当支出超出预算预算时,而不是使预算变为负数时,预算将减少为零,并且从储蓄中提取余额。 Where I really begin to encounter problems is when I do this for more than one expense. 我真正开始遇到问题的地方是当我为此付出不止一个费用时。

Sample Budget: 预算示例:
在此处输入图片说明

So for Food, I budgeted $600 (D2) but spent $820 (D1). 因此,对于“食物”,我预算了600美元(D2),但花了820美元(D1)。 I want the sheet to read the money remaining for Food (D2) to be $0 and then the money remaining for Savings (D5) to be $39,780. 我希望工作表读取的食物(D2)的剩余金额为$ 0,然后储蓄(D5)的剩余金额为$ 39,780。 But things get much more complicated when we find out that we also overspent on Vacations which makes money remaining for Vacations (D4) to be $0 and money remaining in Savings to be $38,280 because it covered the overflow costs of both Food and Vacations (and would have covered any overspending from Clothing as well, if there had been any). 但是,当我们发现假期也超支时,事情就变得更加复杂了,假期(D4)的剩余资金为$ 0,而储蓄中的剩余资金为$ 38,280,因为它涵盖了食品和度假的溢出成本(并且也涵盖了服装的任何超支情况(如果有的话)。

I am stumped on this problem. 我为这个问题感到困惑。 I have tried several approaches and would really appreciate any help you guys could give on this. 我尝试了几种方法,非常感谢你们在此方面提供的任何帮助。

I think all you've got to do is, in column D (remaining), make the formula in cell D2 (for example): 我认为您要做的就是在D列(剩余)中,在单元格D2中创建公式(例如):

=IF(C2<B2,0,C2-B2)

Then for savings, it's equal to your starting amount (40000), minus what you spent, plus what you budgeted, minus the "remaining" amount (which I assume was already pulled out of savings): 然后,对于储蓄,等于开始金额(40000)减去支出,再加上预算,再减去“剩余”金额(我认为已经从储蓄中提取了):

=40000-SUM(B2:B4)+SUM(C2:C4)-SUM(D2:D4)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM