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

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?


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

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.