简体   繁体   English

如何使用一个单元格的输入来添加或减去 Google 表格中的另一个单元格?

[英]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.

相关问题 Google表格可以将一个单元格更改为另一个单元格 - Google Sheets change one cell from another 如何使用谷歌表格中的脚本将图像从一个单元格复制到另一个单元格? - How can I use a script in google sheets to copy an image from one cell to another? 谷歌表格我可以使用超链接从一个单元格跳转到另一个单元格并将数据复制到另一个单元格吗 - Google sheets can I use hyperlink to jump from one cell to another and copy data to the other cell 使用Google表格中的单元格值作为输入,使用Google App脚本将文件从一个文件夹移动到另一个文件夹 - Using a cell value in Google Sheets as an input to move a file from one folder to another using Google App Script onEdit 特定单元格将数据从一个谷歌表格复制到另一个 - onEdit specific cell copy data from one google sheets to another 从另一个单元格中减去一个单元格中的值的脚本 - scrips to subtract value in one cell from another cell 谷歌表格复制一个单元格并粘贴到另一个单元格 - Google Sheets Copy one Cell and paste into another Cell 如何从一个工作表获取(或设置)单元格值到Google表格中的另一个工作表? - How to Get (& Set) cell values from one sheet to another in Google Sheets? 通过单击 Google 表格中的图标,将单元格值从一个单元格自动复制到另一个工作表 - Autocopy cell value from one cell to another sheet by clicking an icon in google sheets 如何从 Google Sheets Apps 脚本中的多个单元格返回数据? - How can I return data from more than one cell in Google Sheets Apps Script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM