0

I added a Google Apps Script for 'Last Update' to my entire spreadsheet. This script automatically puts the date in the last cell in the row that you are editing. But I have a header row that I want static text in, and when I try to type in the last cell in that row, it overwrites with the date.

I can't seem to turn it off by going to Tools> Script Editor.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
  • 3
    Possible duplicate of [Google Spreadsheet SCRIPT Check if edited cell is in a specific range](https://stackoverflow.com/questions/12583187/google-spreadsheet-script-check-if-edited-cell-is-in-a-specific-range) – Mogsdad Jan 13 '18 at 16:21

1 Answers1

0

You aren't specific in your question, but it sounds like you're using an onEdit trigger function to set a "last updated" column.

Just check if the current row is within the header, and exit the trigger. Something like this:

function onEdit(e)
{
  var rr = e.range;
  var ss = e.range.getSheet();

  var headerRows = 1;  // # header rows to ignore

  if (rr.getRow() <= headerRows) return;
  ...

Here's your onEdit, after combining with the suggestion above. In one of these trigger functions, you want to invest as little as possible before checking whether you should bail out. You'll note that the check for headers is at the top of the function, for efficiency. Unnecessary lines have been commented out, for the same reason.

function onEdit(event) {
  // note: actRng = the cell being updated
  var actRng = event.range;
  var headerRows = 2;
  if (actRng.getRow() <= headerRows) return;

  var sheet = actRng.getSheet(); 
  //var index = actRng.getRowIndex();
  //var cindex = actRng.getColumnIndex();
  var dateCol = sheet.getLastColumn();
  var lastCell = sheet.getRange(index, dateCol);
  var date = Utilities.formatDate(new Date(), "GMT", "MM-dd-yy");
  lastCell.setValue("'" + date);
}
Mogsdad
  • 44,709
  • 21
  • 151
  • 275