I have the following function that adds the latest edit time to the L1 cell in our spreadsheet -

function onEdit(e) {
    // Prevent errors if no object is passed.
    if (!e) return;
    // Get the active sheet.
        // Set the cell you want to update with the date.
        // Update the date.
    .setValue(Utilities.formatDate(new Date(), "GMT-6:00", "''MM-dd-yyyy hh:mm:ss aa"));

This is working as intended and seems to be OK - but I would like to exclude a specific sheet when running the function.

Say I have 6 tabs/sheets - Line1, Line2, Line3, Line4, Line5, Data Sheet

I would like the function to continue working for each of the "Line" tabs, but not apply to the Data tab as this has information in the L1 cell that needs to stay. Is there anything simple I can add to this function that excludes the "Data Sheet" from applying the latest edit time?


1 Answer 1


You could introduce a JavaScript if statement like in the following script

function onEdit(e){
  // if active sheet name is Data Sheet then stop
  if(e.range.getSheet().getName() === 'Data Sheet') return;
  // Add here the things to do when active sheet name isn't Data Sheet


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.