我希望我的意图很明确。它用于库存管理。第一个单元格显示当前库存,第二个单元格只是一个单元格,您可以在其中输入条目或流出。我认为 Excel 的代码应该是这样的,但我正在寻找相应的 Google 电子表格:
Sub LagerNeu()
Dim S As Integer
[F2].Select
S = ActiveCell.Value + ActiveCell.Offset(0, 1).Value
ActiveCell.Value = S
ActiveCell.Offset(0, 1).Value = 0
End Sub
最佳答案
使用 onEdit()方法可以监视 F
的更改列并根据需要更新单元格
示例:
function onEdit(e) {
var range = e.range; // e.g F2 is edited
// Only runs if the edit is in column F
if (range.getColumn() == 6) {
var old_value = range.offset(0, -1).getValue();
// Set the new value to the cell in the column to the left - E2
range.offset(0, -1).setValue(Number(old_value) + Number(e.value));
// Reset F2 to zero
range.setValue(0);
}
}
关于vba - 添加单元格一 + 单元格二并将单元格二重置为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46867588/