【问题标题】:On google sheets, is there a reason this code isnt running?在谷歌表格上,这段代码没有运行是有原因的吗?
【发布时间】:2020-01-29 15:13:21
【问题描述】:
function onEdit(if getActiveRange()=A3:B500) {//Check to see if the cells edited are on this 
    rangemyFunction1(event);// trying to set off this function that has other functions nested

【问题讨论】:

  • 这是整个代码吗? rangemyFunction1 在哪里?为什么函数的参数部分有一个 if?
  • 这是从您的实际代码中复制/粘贴的吗?脚本编辑器甚至不允许您使用呈现的语法保存脚本,这不是有效的 Javascript 语法。我可以帮助您重写它,但要确保所提出的问题不只是拼写错误或复制/粘贴错误。
  • 它的实际代码副本我只是无法让它工作,我试图让它检查这个特定范围 A:B 列的编辑,然后执行一些代码

标签: google-apps-script google-sheets


【解决方案1】:

问题

为什么我的代码不起作用?

回答

错误的 javascript 语法

您的代码无法运行,因为您的 JavaScript 语法错误,因为您无法在参数中编写 if 语句

function onEdit(if getActiveRange()=A3:B500) {//Check to see if the cells edited are on this 
    rangemyFunction1(event);// trying to set off this function that has other functions nested

相反,您必须编写如下内容:

function onEdit() {
    if (getActiveRange() === "A3:B500") {
        rangemyFunction1(event);
        // do more stuff
    }
    // do other stuff
}

检查developers.google.com上的onEdit example

更多示例herehere

【讨论】:

    猜你喜欢
    • 2019-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-20
    • 2022-11-02
    • 2017-02-22
    • 1970-01-01
    相关资源
    最近更新 更多