Search code examples
google-apps-scripttriggersgoogle-sheetsonchangegoogle-apps-script-editor

How to determine which row has changed/updated on Google Sheets Script Editor


For my google sheets, each row gets populated at random, but when it does get populated, I want a function to run. Each time something gets populated, it's the next row (it's not a cell or a random row).

I have the onChange trigger running right now. It is set to "run FunctionA from Spreadsheet on change". In that function, how do I grab the row that has been specifically changed/updated? What is the function/method I would use to manipulate whatever that row is?

I searched around but couldn't find an appropriate answer.


Solution

  • You should use the onEdit spreadsheet event. (https://developers.google.com/apps-script/guides/triggers/events)

    You can call it this way :

    function onEdit(e){
        //Access the range with your parameter e.
        var range = e.range;
        var row = range.getRow();
        var column = range.getColumn();
        //do whatever you need with that range
    }
    

    It will automatically run when there is an edit on a cell of the spreadsheet.