On Edit function doesn't work when cells are pasted into on Google sheets

Viewed 37

I'm working on spreadsheet and used the below onEdit function to populate 2 timestamps when cells are edited. However when the cells are pasted into it doesn't trigger the timestamp. Is there any other function the will trigger when cells are pasted into, so when the value changed in a cell?

function onEdit(e) {
  const sh = e.range.getSheet();
  if (sh.getName() == "BOM" && e.range.rowStart > 1) {
    if (e.range.columnStart == 1) {
      sh.getRange(e.range.rowStart, 30).setValue(new Date());
    } else if (e.range.columnStart == 20) {
      sh.getRange(e.range.rowStart, 31).setValue(new Date());
    }
  }
}
1 Answers

Try it this way:

function onEdit(e) {
  const sh = e.range.getSheet();
  if (sh.getName() == "BOM" && e.range.rowStart > 1) {
    let l = e.range.rowEnd - e.range.rowStart + 1;
    if (e.range.columnStart == 1) {
      sh.getRange(e.range.rowStart, 30, l).setValue(new Date());
    } else if (e.range.columnStart == 20) {
      sh.getRange(e.range.rowStart, 31, l).setValue(new Date());
    }
  }
}
Related