0

I noticed this code from a thread I was reviewing as I needed the same functionality to provide a timestamp when a particular row is edited in a Google Spreadsheet;

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

It works perfectly I was able to determine how to modify it to place the timestamp in column R which suited my needs but is there a simple way to make it ignore Row 1 which is the column headers?

  • I believe the original answer was provided by answered Oct 8 '12 at 20:06 OnenOnlyWalter – Jhelum Davis Jan 16 '14 at 17:40
1

You just need to wrap an extra conditional around the "stamping" code. Check the row value and only execute the stamping part if the row is NOT 1.

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  var r = s.getActiveCell();
  if( r.getColumn() != 18 ) { //checks the column
    var row = r.getRow();
    if (row != 1) {
      var time = new Date();
      time = Utilities.formatDate(time, "GMT-08:00", "MM/DD/yy, hh:mm:ss");
      SpreadsheetApp.getActiveSheet().getRange('B' + row.toString()).setValue(time);
    };
  };
 };

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.