Google-sheets – Multiple timestamps in multiple columns on multiple Google Sheet tabs

google sheetsgoogle-apps-scriptgoogle-sheets-timestamp

I am trying to work out what script is required to have multiple timestamps on several tabs however each one I have tried doesn't work for me. I am new to this.

When text is added to column 2 I need a timestamp in column 1. When text added in 8 I need a timestamp in 7. When 15 which is a checkbox, a timestamp in 16, and when 18, timestamp in 17. Is this possible to have so many?

My current script is as follows and this is giving me the time stamp in column 1 when column 2 is amended and it doesnt overwrite when it is changed a second time.

function onEdit(e) {
  var row = e.range.getRow();
  var col = e.range.getColumn();
  if (col === 2 && row > 1 && e.source.getActiveSheet().getName() === "June 2021") {
    if (e.source.getActiveSheet().getRange(row, 1).getValue() == "") {
      e.source.getActiveSheet().getRange(row, 1).setValue(new Date());
    }
  }
}

Best Answer

A single onEdit(e) function can watch multiple columns on multiple sheets and insert timestamps in multiple columns depending on which column was edited and what the new value in the cell is. See the timestampMultipleColumns_ script for an example.