[英]How can the input of one cell be used to add or subtract from another cell in Google Sheets?
I'd like to build a simple Google sheets that helps me keep track of my D&D campaign's resources.我想构建一个简单的 Google 表格,以帮助我跟踪 D&D 活动的资源。 Specifically, how can I have blank cell (say like one with the placeholder tag "update value") that adds the input number to a specific cell (say if I input "+34" or "-21")?
具体来说,我怎样才能让空白单元格(比如带有占位符标签“更新值”的单元格)将输入数字添加到特定单元格(比如我输入“+34”或“-21”)? And I'd like the input cell to to back to being blank afterwards.
我希望输入单元格在之后恢复为空白。
There is no built-in feature that does that but you could use a Google Apps Script trigger.没有内置功能可以做到这一点,但您可以使用 Google Apps 脚本触发器。
You might have to start by reading https://developers.google.com/apps-script/guides/sheets then https://developers.google.com/apps-script/guides/triggers .您可能必须先阅读https://developers.google.com/apps-script/guides/sheets然后https://developers.google.com/apps-script/guides/triggers 。
The following is a simple example of using a simple on edit trigger to update the value of the cell on the left of the edited cell.下面是一个简单的例子,它使用简单的编辑触发器来更新编辑单元格左侧的单元格的值。
function onEdit(e){
const placeholder = '<update value>';
if( e.oldValue === placeholder ){
/** Modify the cell to the left */
let target = e.range.offset(0,-1);
target.setValue(target.getValue() + e.value);
e.range.setValue(placeholder);
} else {
// do nothing
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.