Google Sheets Apps Script to insert timestamp when specific users edits specific columns

188 views
Skip to first unread message

Tiffany Meinhardt

unread,
Nov 10, 2022, 2:43:45 PM11/10/22
to Google Apps Script Community
I am looking for help to revise the code below so that a timestamp is inserted in column AA if I edit cells in columns F-R and another timestamp in column AB cells, only when my colleague edits the cells in columns Y-Z. Currently, my script inserts a timestamp when any cell is edited/added (by any user) in columns A-Z. 

function onEdit(e) {
    var rr = e.range;
    var ss = e.range.getSheet();
    var headerRows = 1; // # header rows to ignore
    if (rr.getRow() <= headerRows) return;
    const sh = e.range.getSheet();
    if (sh.getName() == "2022 Agreement Tracker") {
    var dt = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), "M/d/yy - h:mm a - ");
    var usern = e.user.getUsername();
    sh.getRange(e.range.rowStart,27).setValue(dt + user);
  }
}

N A

unread,
Nov 12, 2022, 7:24:58 AM11/12/22
to Google Apps Script Community
You can try this. The ... means the code is the same as above.

function onEdit(e) {
    ...
    if (...) {
        ...
        const column = (usern == "my_username") ? 27 : 28;
        sh.getRange(e.range.rowStart, column).setValue(dt + user);
    }
}

Reply all
Reply to author
Forward
0 new messages