目前,以下脚本会自动在包含其历史记录的 A 列单元格中添加注释,同时它会自动将今天的日期添加到 B 列中旁边的单元格(在标题为“1”的工作表中)。我希望将注释添加到触发的单元格(B 列)中,而不是 A 列中的单元格中。在每列中创建单独的注释也很有用。有人可以帮我解决这个问题吗?提前致谢!这是脚本:function onEdit(e){{ var sh=e.range.getSheet(); var A1=sh.getRange(e.range.rowStart,e.range.columnStart).getA1Notation(); if( sh.getName() == "1") { var rg=sh.getActiveCell(); if( rg.getColumn() == 1 ) { var nextCell = rg.offset(0, 1); nextCell.setValue(new Date()); var dt=Utilities.formatDate(new Date(),Session.getScriptTimeZone(),"MM/dd/yyyy HH:mm:ss") var newNote=Utilities.formatString('Last Modified:%s cell:%s Value:%s\n',dt,A1,e.value); rg.setNote(rg.getNote() + newNote);} } }}
1 回答

富国沪深
TA贡献1790条经验 获得超9个赞
如果删除条件 (if),您发布的脚本应该可以正常工作,因为您不想将其限制为特定列。例如:
function onEdit(e){
var sh=e.range.getSheet();
var A1=e.range.getA1Notation();
var editDate = Utilities.formatDate(new Date(),Session.getScriptTimeZone(),"MM/dd/yyyy HH:mm:ss");
var nextCell = e.range.offset(0, 1);
nextCell.setValue(editDate);
var newNote=Utilities.formatString('Last Modified: %s / Updated Cell: %s / Updated Cell Value: %s / Associated Date Cell: %s / Associated Date Cell Value: %s\n',editDate,A1,e.value,nextCell.getA1Notation(),editDate);
nextCell.setNote(nextCell.getNote() + newNote);
}
添加回答
举报
0/150
提交
取消