2

I've been working on a shared Google spreadsheet on Google Drive. The document has different sheets with a "Last Modified Date" Cell. I found an script for this to be auto-filled searching here:

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-08:00", "MM/DD/yy, hh:mm:ss");
    SpreadsheetApp.getActiveSheet().getRange('B' + row.toString()).setValue(time);
  };
};

The script works perfectly, I just changed the column and it worked! The thing is, I need to apply this script to every sheet but the first one. How can I deactivate the use of the script in the first sheet?

2

You can test if the active sheet is the first sheet with

sheet.getIndex() == 1

(doc)

So your function can be

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if (s.getIndex() == 1) {
     return; // Don't do anything for first sheet
  }
  var r = s.getActiveCell();
  if( r.getColumn() != 2 ) { //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);
  };
};
0

Use this little script, to skip the first sheet

Code

function onEdit(e) {
  if(e.source.getActiveSheet().getSheetId() != 0 && e.source.getActiveCell().getColumn() != 2) {
    var row = e.source.getActiveCell().getRow(); 
    var time = Utilities.formatDate(new Date(), "GMT-08:00", "MM/DD/yy, hh:mm:ss");
    e.source.getRange('B'+row).setValue(time);
  }
}

Example

See example file I created: little script

  • Thanks for the response! I tried it, but still stamps the date on the first sheet! :s – user62551 Mar 6 '14 at 20:42
  • @user62551 Then you're doing something wrong, I works in my sheet. – Jacob Jan Tuinstra Mar 6 '14 at 20:45
  • I'd might be @Jacob-Jan-Tuinstra but thanks anyway! – user62551 Mar 7 '14 at 16:07

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.