[英]I am trying to run the onEdit function for three separate tabs but receiving TypeError: Cannot read property 'value' of undefined
[英]Prevent onEdit to run on some tabs
我在编辑Col 6时使用此脚本自动为Col 1加上日期
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);
}
工作完美
为了防止此onEdit不能在某些选项卡上运行,我该怎么做?
谢谢 !
您可以定义一组选项卡以排除,然后检查当前工作表是否在排除项中。 在第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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.