Home > database >  Google sheet onChange trigger for single row change
Google sheet onChange trigger for single row change

Time:05-27

I want to run copy function with row 1 change in Sheet1 By onChange trigger but i can not do it, please let me know is there any way

function copy()
{
      var ss=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
      var lr=ss.getLastRow();
      ss.getRange("A1:CZ1").copyTo(ss.getRange(lr 1,1,1,104),{contentsOnly:true});
}

CodePudding user response:

Try:

function onChange(e) {

  if (e.source.getActiveSheet().getName() === `Sheet1`) {

    if (e.source.getActiveRange().getRow() === 1) copy()

  }

}

CodePudding user response:

Try it like this:

function onEdit(e) {
  if(e.range.rowStart != 1 || e.range.getSheet().getName() != "Sheet1") return;
  var ss=SpreadsheetApp.getActive().getSheetByName("Sheet1");
  var lr=ss.getLastRow();
  ss.getRange("A1:CZ1").copyTo(ss.getRange(lr 1,1),{contentsOnly:true});
}
  • Related