简体   繁体   中英

Google Sheet Script - onChange

Please help with Google onChange function Sheet Script. I only want to log onChange for one sheet "Attendance" the change on this sheet is then logged in "Sheet5" When there is a change in "Attendance" column C, then copy the value of column B into "Sheet5" and add the current date and time. Here is some code I tried, but do not know how to change it.

function createSpreadsheetOpenTrigger() {

   ScriptApp.newTrigger('onChange')
    .forSpreadsheet('ID to go here')
   .onChange()
   .create();

    }

function onChange(e) {

  const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet5");
  const lastRow = sheet.getLastRow();

  sheet.getRange(lastRow + 1,1,1,4).setValues([
    [e.changeType,
      e.source.getSheetName(),
      e.source.getActiveSheet().getActiveRange().getValue(),
     new Date()]
    ]);
   }

Try this:

function onEdit(e) {
  const sh=e.range.getSheet();
  if(sh.getName()=='Attendance' && e.range.columnStart==3 && e.range.rowStart>'Your header row') {
    e.source.getSheetByName("Sheet5").appendRow([e.range.offset(0,-1).getValue(),new Date()]);
  }
}

onedit event obj

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