在使用以下代码在5个特定的单元格中插入ArrayFormulas时,我遇到了Googles Apps脚本的一些问题:
function AddForm() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
const sh=ss.getSheetByName('sheetname');
var cell = sheet.getRange("Z2");
cell.setFormula('=iferror(arrayformula(vlookup(J2:J,othersheetname!$L:$M,2,false)),"")');
var cell = sheet.getRange("AA2");
cell.setFormula('=iferror(arrayformula(vlookup(K2:K,othersheetname!$P:$Q,2,false)),"")');
var cell = sheet.getRange("AB2");
cell.setFormula('=iferror(arrayformula(vlookup(K2:K,othersheetname!$P:$Q,2,false)),"")');
}
我收到“ ReferenceError:未定义Run_AddForm”错误消息,并且不明白为什么。
有人可以帮忙吗?
在此先感谢您的支持
这是仍然存在问题的通话功能:
function ManualSGAConso() {
Run_MID2019();
Run_2019SC();
Run_MID2020();
Run_AddForm();
}
答案 0 :(得分:2)
首先,您在AddForm()函数中犯了一个小错误:
sh 应该是工作表
function AddForm() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet=ss.getSheetByName('sheetname');
var cell = sheet.getRange("Z2");
cell.setFormula('=iferror(arrayformula(vlookup(J2:J,othersheetname!$L:$M,2,false)),"")');
var cell = sheet.getRange("AA2");
cell.setFormula('=iferror(arrayformula(vlookup(K2:K,othersheetname!$P:$Q,2,false)),"")');
var cell = sheet.getRange("AB2");
cell.setFormula('=iferror(arrayformula(vlookup(K2:K,othersheetname!$P:$Q,2,false)),"")');
}
由于收到的错误消息正在寻找Run_AddForm()函数,请尝试将 Run_AddForm()替换为 AddForm():
function ManualSGAConso() {
Run_MID2019();
Run_2019SC();
Run_MID2020();
AddForm();
}