Google-sheets – Auto-updating column in Google Spreadsheet in a specific sheet

google sheets

I'm using a function that I found on another thread here on stackexchange, but I would like to limit the function to only work in 1 specific sheet at the time.

I have old sheets with history that is overwritten if there is a change in those sheets.

The function I use:

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+02:00", "dd.MM.yyyy, HH:mm");
    SpreadsheetApp.getActiveSheet().getRange('T' + row.toString()).setValue(time);
  };
 };

I'm guessing I have to add the name of the sheet within getRange?

Best Answer

Found it out myself for those needing help.

Use getSheetByName(Name)

function onEdit() {
  var s = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('UPDATE');
  var r = s.getActiveCell();
  if( r.getColumn() != 2 ) { //checks the column
    var row = r.getRow();
    var time = new Date();
    time = Utilities.formatDate(time, "GMT+02:00", "dd.MM.yyyy, HH:mm");
    SpreadsheetApp.getActiveSpreadsheet().getSheetByName('UPDATE').getRange('T' + row.toString()).setValue(time);
  };
 };