简体   繁体   中英

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. 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")? 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.

You might have to start by reading https://developers.google.com/apps-script/guides/sheets then 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
  }
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM