[英]Excel VBA code to subtract
I have the following table 我有下表
Bills Amount Paid
Food $100 No
Gas $200 Yes
Car $300 Yes
Total $600
Total left to pay: $400
And I have the following code 我有以下代码
Sub Bills()
Range("C2").Select
Do Until IsEmpty(ActiveCell)
If ActiveCell = "Yes" Then Range("B6") = Range("B5") - ActiveCell.Offset(0, -1)
ActiveCell.Offset(1, 0).Select
Loop
End Sub
But it only subtracts the first "Yes" and when I change another to "Yes" i do not see were is getting the new amount to subtract it from. 但是它只减去第一个“是”,而当我将另一个改为“是”时,我看不到正在获得新的数量来减去它。 what am I missing?
我想念什么?
Goal: Whenever I have paid a bill and come here and select "Yes" and run the code it will subtract it from the total and show me how much I still have left to pay on bills. 目标:每当我支付账单并来到这里并选择“是”并运行代码时,它将从总数中减去并显示我还有多少钱可以支付账单。
Thanks in advance 提前致谢
假设B列是“金额”列,C列是“已支付”列,只需将单元格中的公式用于“剩余支付”即可
=SUMIF(C2:C4,"=NO",B2:B4)
您可以使用Formula
来计算“已付费Column
:
=SUMIF(C2:C4;"No";B2:B4)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.