onEdit事件仅适用于一张纸 [英] onEdit event applicable to only one sheet
本文介绍了onEdit事件仅适用于一张纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对编码非常陌生。我可以让此脚本在文档中的所有工作表上使用,但不能仅在其中一张工作表上使用。我看过类似的问题和答案,但无法使它们适用于此脚本:(
I'm pretty new to coding. I can get this script to work across all sheets in the document however can't get it to work on just 1 of the sheets. I have looked at similar questions and answers but can't get them to apply to this script :(
我尝试添加if(sheet.getName()=
I have tried to add in if(sheet.getName() == "Delivery Tracking") but then the script won't work at all.
function onEdit(event)
{
var ss = event.source.getActiveSheet();
var r = event.source.getActiveRange();
if(r.getColumn() == 9){ //To check if update cell in Column I, 1 means first column.
ss.getRange('P'+r.getRow()).setValue(new Date()); //Set column P1 value to current date.
}else{
ss.getRange('P'+r.getRow()).setValue('');
}
}
推荐答案
这可能是因为未定义。查看是否可行:
That's probably because is nowhere defined. See if this works:
function onEdit(event) {
var sheet = event.source.getActiveSheet();
if(sheet.getName() !== 'Delivery Tracking' || event.range.columnStart
!== 9) return;
event.range.offset(0, 7).setValue(event.value ? new Date() : '');
}
这篇关于onEdit事件仅适用于一张纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文