Google-sheets – Google Spreadsheet Timestamp on Edit

google sheetsgoogle-apps-scriptgoogle-sheets-timestamp

I got the major part of answer on this link:
Google Spreadsheet Timestamp?

The code on this link is below:

function onEdit() {
 var s = SpreadsheetApp.getActiveSheet();
 if( s.getName() == "Sheet1" ) { //checks that we're on the correct sheet
   var r = s.getActiveCell();
   if( r.getColumn() == 13 ) { //checks the column
     var nextCell = r.offset(0, 1);
     if( nextCell.getValue() === '' ) //is empty?
       var time = new Date();
       time = Utilities.formatDate(time, "GMT", "HH:mm:ss");
       nextCell.setValue(time);
   };
 };
}

I want a little modification to third line of code which I cant achieve. I want to apply the same code to sheet1, sheet4, and sheet 10. How I can do that?

Best Answer

See if this works:

function onEdit(e) {
var s = e.source.getActiveSheet(),
    sheets = ['Sheet1', 'Sheet4', 'Sheet10'],
    nextCell = e.range.offset(0, 1);
if (sheets.indexOf(s.getName()) === -1 || e.range.columnStart !== 13 || nextCell.getValue() !== '') return;
nextCell.setValue(Utilities.formatDate(new Date(), "GMT", "HH:mm:ss"));
}