0

This question is an exact duplicate of:

I am using this script to add in a date whenever a row is edited. I want it to ignore the first row. Thoughts on how to do this?

function onEdit() { 
    var s = SpreadsheetApp.getActiveSheet(); // Get spreadsheet name 
    var r = s.getActiveCell(); // store active cell name in current spreadsheet 
  var cell1 = 2 // This is the row I want to put values
  if(r.getColumn() != cell1) { // Ignores this row (where I put the dates)
    var row = r.getRow();  // Get column # from active cell
    var time = new Date(); // Get date and time of last mod
    time = Utilities.formatDate(time, "GMT-05:00", "MMM dd 20yy, hh:mm"); // Format date and time
    SpreadsheetApp.getActiveSheet().getRange('B' + row.toString()).setValue(time);
  };
 };

marked as duplicate by Rubén, John C, serenesat, jonsca Aug 8 at 22:50

This question was marked as an exact duplicate of an existing question.

1

Figured it out:

function onEdit() { 
    var s = SpreadsheetApp.getActiveSheet(); // Get spreadsheet name 
    var r = s.getActiveCell(); // store active cell name in current spreadsheet 
    var cell1 = 2 // This is the row I want to put values

    var headerIndex = 1;
    var isHeader = r.getRow() === headerIndex;

    if(r.getColumn() != cell1 && !isHeader) { // Ignores this row (where I put the dates)
      var row = r.getRow();  // Get column # from active cell
      var time = new Date(); // Get date and time of last mod
      time = Utilities.formatDate(time, "GMT-05:00", "MMM dd 20yy, hh:mm"); // Format date and time
      SpreadsheetApp.getActiveSheet().getRange('B' + row.toString()).setValue(time);
    };
 };

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