Reputation: 12571
I have a relatively large spreadsheet (300 rows, 30 columns) that I color based on the values in the spreadsheet. I'm doing accessing the API minimally using only two accesses:
getValues(...)
to access all the values of the data range.setBackgrounds(...)
to set all the backgrounds of the data range.This runs in about half a second or less. However, it gets in the way if I make it run on every edit using onEdit()
, but I also don't want it to be updated at regular time intervals when I'm not editing it, seems like a waste. Is there a good way to make the script run in a "delayed" way, updating at regular time intervals while I'm editing?
Upvotes: 2
Views: 2650
Reputation: 1424
Firstly, I would say you should look at Google Sheets' conditional formatting (Format > Conditional formatting menu item in Sheets) -- you may be able to do much of what you need without involving Apps Script at all.
Failing that, you can set up a regular time-based trigger to check for edits and change the backgrounds appropriately. You can support this trigger with a separate onEdit() trigger to record what has changed internally. The flow goes like this:
That said, depending on your workflow this approach may not be much better than simply using a time trigger to change the cells directly.
Upvotes: 2