1

I am using this script in order to put a time stamp in column B when someone edits in a row. However, I need it to place the time stamp if someone edits a row in column A. I don't need it to place a stamp every time someone makes a change on the rest of the sheet. Can someone tell me what I need to change on this script in order for the time stamp to only be placed in columb B if the cell to the left of it in column A is edited?

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  var r = s.getActiveCell();
  if( r.getColumn() != 2 ) { //checks the column
    var row = r.getRow();
    var time = new Date();
    time = Utilities.formatDate(time, "GMT-05:00", "MM/dd/yy, h:mm a");
    SpreadsheetApp.getActiveSheet().getRange('B' + row.toString()).setValue(time);
  };
 };
3

The "if" conditional should check whether the edited column has number 1. So it's ...getColumn() == 1 instead of ...getColumn() != 2.

In addition, I simplified the script which wasn't particularly well written. Using the event object, and its range property, eliminates the need for most of that code.

function onEdit(e) {
  if (e.range.getColumn() == 1) {                // check if the edit was in column A 
    e.range.offset(0, 1).setValue(new Date());   // put timestamp one cell to the right
  }
}
1

Thanks - this really worked (the original code).

The advantage of using getColumn() != 2 is that it will change the timestamp when any cell is edited, other than the timestamp itself in Column 2 (which would produce an endless loop.)

Instead of GMT-5, I used Google's "America/New_York", which seems to adjust for DST. See https://developers.google.com/google-ads/scripts/docs/features/dates.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.