2

I have this Script so far,

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);
  };
 };

but what I am trying to get this to only run on one of my Google Sheet tabs. Tried adding

var sheet = event.source.getActiveSheet();
  if(sheet.getName()=='Inventory'){

But I couldn't get it to work

2 Answers 2

2

Checking the name of the sheet would be like this:

function onEdit() {
  var s = SpreadsheetApp.getActiveSheet();
  if (s.getName() == 'Inventory') {
    // the rest of the script
  }
}

The line you were trying, with event.source.getActiveSheet() would work if you actually took the event object as a parameter: onEdit(event).

function onEdit(event) {
  var s = event.source.getActiveSheet(); 
  //  etc
}   
0

Adding additional cell (which can be hidden after) to copy changing cell's data (... .setValue(time)) and manipulate the data in other sheets can be a quick solution in some variants.

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.