Home > Mobile >  Appscript Triggers on pasting values
Appscript Triggers on pasting values

Time:11-10

I got this script working, but i want it to trigger, the moment i paste the values onto spreadsheet "raw Data", instead of manually running it.

function deleteColumns() {
  var sh1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("raw Data")
  sh1.deleteColumn(1)
  sh1.deleteColumn(3)
  sh1.deleteColumns(4,3)
  sh1.deleteColumns(8,7)

}

CodePudding user response:

One way to do that is to use an onEdit(e) simple trigger, like this:

/**
* Simple trigger that runs each time the user hand edits the spreadsheet.
*
* @param {Object} e The onEdit() event object.
*/
function onEdit(e) {
  if (!e) {
    throw new Error(
      'Please do not run the onEdit(e) function in the script editor window. '
        'It runs automatically when you hand edit the spreadsheet. '
        'See https://stackoverflow.com/a/63851123/13045193.'
    );
  }
  if (e.range.getSheet().getName() === 'raw Data') {
    deleteColumns();
  }
}

The function will delete columns every time you manually modify the 'raw Data' tab. To do that only when certain types of events take place, use an "on change" installable trigger.

  • Related