简体   繁体   中英

Edit cell above cell that called a function? - Google Sheets apps script

I'm using Google Apps Script to make a function that will be called in a Google Sheet. The function does some auto calculating for a spell effect. Some spells need the player to provide extra info (How many people are you shielding, etc) and some don't need any additional inputs. If extra info is needed, the user provides it in the cell directly above the cell that calls the function. I'll call this the "input cell" for clarity. The "function cell" is the one that calls the function, directly below the input cell.

My question is this: if the extra info is unneeded, as determined by conditionals within the function, how do I overwrite the contents of the input cell with '-'? I can't put a formula within that cell directly, because the user would overwrite the formula when entering the additional information. The function also returns a value to the cell that called it.

I've tried a bunch of techniques but I can't figure out how to do it.

  • I tried returning an array of both values, but it flows downwards instead of upwards, and I couldn't find anything for "return array offset upwards" or something to that effect.
  • I can't use absolute references like "L17" because the function can be called from many places on the sheet, and it also only needs to mess with the cell directly above it.
  • using setValue() or setValues() threw a "no permission" error.

I would attach my code, but it's a mess of half-deleted attempts that didn't work, and wouldn't be much help at all. I also don't want to ask anything too specific, for fear of running into the https://xyproblem.info problem. I just want to be able to have a function edit the cell directly above it, and I don't care about which technique gets that accomplished.

Any help is greatly appreciated. Thank you!

No cell can contain both a formula(or a output of a formula) and simultaneously contain a user entered value. That was always the case with any spreadsheet, Excel or Google sheets or any other. It's one or the other. Choose one and redraw your logic!

For your specific problem, if you can reflow your logic, you might try simple triggers like onEdit .

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