Google Sheets – Auto Update Cells with Timestamp

google sheetsgoogle-apps-scriptgoogle-sheets-timestamp

I'm new to writing/using scripts. I want to use something to allow for multiple cells to be updated and tracked for the last time they were modified. I've tried various different scripts on here but so far I'm struggling!! I'd really appreciate some help/guidance on how to say if cell M / N / O are modified then the last date that happened ends up in V / W / X.

Best Answer

  • try like this:

    function onEdit(e) {
    var s = SpreadsheetApp.getActiveSheet();
    if( s.getName() == "Sheet3" ) { 
    var r = s.getActiveCell();
    if( r.getColumn() == 13 ) { 
      var nextCell = r.offset(0, 9);
      var newDate = Utilities.formatDate(new Date(), 
      "GMT+8", "MM/dd/yyyy hh:mm:ss");
      nextCell.setValue(newDate);
    }
    if( r.getColumn() == 14 ) { 
      var nextCell = r.offset(0, 9);
      var newDate1 = Utilities.formatDate(new Date(), 
      "GMT+8", "MM/dd/yyyy hh:mm:ss");
      nextCell.setValue(newDate1);
    }
    if( r.getColumn() == 15 ) { 
      var nextCell = r.offset(0, 9);
      var newDate1 = Utilities.formatDate(new Date(), 
      "GMT+8", "MM/dd/yyyy hh:mm:ss");
      nextCell.setValue(newDate1);
    }
    }
    }

  • "Sheet3" = sheet name

  • r.getColumn() == 13 = column M / 13th column
  • r.offset(0, 9) = offset timestamp 9 columns to the right on the same row eg column V
  • "GMT+8" = timezone
  • "MM/dd/yyyy hh:mm:ss" = date and time format

    0