Search code examples
google-sheetsupdatescells

Auto updating a date in a cell when another cell is edited - Google Sheets


I have looked at various scripts etc. on this site which should solve my query but none of them seem to work.

Basically I have a Google Sheet where members can update a figure in column F. They should also change the edit date in column G but invariably forget that, so I am looking to automate it.

I am a complete novice when it comes to writing scripts etc but, as I have said, none of those I have tried have worked.

Any suggestions?


Solution

  • I tried this one earlier and it didn't work but I have just tried again and it seems to be doing the job now :)

    function onEdit(event) {
      var sheetName = 'Members',
      watchCol = 6, 
      stampCol = 7,
      r = event.range;
    
      if (r.getSheet().getName() !== sheetName
          || r.columnStart !== watchCol
          || r.rowStart < 2)
        return;
      r.getSheet()
          .getRange(r.rowStart, stampCol)
          .setValue(event.value ? new Date() : null);
    }