简体   繁体   中英

How to fire a Google Script function onEdit of just one particular cell in a sheet?

I have a Google Sheet with a custom script containing a function which I want to fire ONLY when cell A1 is edited. I've got it so that my function runs every time anything in the sheet is edited, but I want it to run only when cell A1 changes (and, ideally, only when it changes to something other than empty or null). Is there a way to do this? This is what I've got at the moment:

function inventoryAdd() {
    // ...custom function stuff... 
}

function onEdit(event) {
    inventoryAdd();
}

there are many ways to do it like inspecting the changed range in the "e" parameter. the easiest way is to simply remember (in script properties service) the last value you saw of that cell (from the previous onEdit call) and compare it with the current value.

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