简体   繁体   中英

Prevent onEdit to run on some tabs

im using this script to auto date Col 1, when I edit Col 6

    function onEdit(e) {

  var colToWatch = 6, colToStamp = 1;
  var timezone = "GMT-6";
  var timestamp_format = "MM-dd-yyyy"; // Timestamp Format. 

  if (e.range.columnStart !== colToWatch) return;
  if (e.source
     .getActiveSheet()
     .getRange(e.range.rowStart, colToStamp)
     .getValue()) {
  return;
}

var date = Utilities.formatDate(new Date(), timezone, timestamp_format);
e.source.getActiveSheet()
    .getRange(e.range.rowStart, colToStamp)
    .setValue(date);
}

is working perfect

What I have to do to prevent this onEdit to don't run on some tabs ?

Thanks !

You can define an array of tabs to exclude then check if current sheet is one among the excludes. Add this code after line 4.

var name = e.source.getActiveSheet().getName();
// enter names of the sheets to exclude, ['Sheet1', 'Sheet2'] etc
var excludes = [];
if (excludes.indexOf(name) != -1) return;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM