[英]Is it possible to subtract the content of one cell from another in excel using formula?
[英]Is it possible to add/subtract in one cell, and have it subtract/add in another cell that already has a value?
是否可以在一個單元格中進行加/減,並在已經具有值的另一個單元中進行減/加? 我認為這可能是一個if函數,但我無法解決如何寫公式的問題。
假設您有2列B和C已經包含數據。 而且,如果您向B添加數字,則希望從C中減去該數字。
我的建議是編寫一個將按以下方式工作的宏:
首先,用戶選擇兩列,然后運行宏
For each row
Cell c = getCell("C" + row);
double cval = c.Value;
c.type = FORMULA;
c.Formula = "=" + (cval + getCell("B" + row).Value) + "-B"+row;
c.Recalculate()
例:
原版的:
A B C
1 Gas 5 10
2 Air 8 12
用。。。來代替:
A B C
1 Gas 5 =15-B1
2 Air 8 =20-B2
因此,您只需更改B,就會自動計算C的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.