插入的公式没有做任何事情
Inserted formula not doing anything
我已将这个小脚本放在一起以将 if(vlookup) 公式插入到电子表格中,但即使它是 运行 它也没有在电子表格中插入任何内容。谁能提出我遗漏或忽略的建议?
或者有没有更简单的方法来使用数组?我还很新,所以不确定如何成功执行。
function idSiteCoordinator(){
var SS = SpreadsheetApp.getActiveSpreadsheet();
var shLog = SS.getSheetByName("LOG");
//declare how many rows to interrogate (to the last row)
var lastRow = shLog.getLastRow();
var startRow = 2;
for (var i=startRow; i<lastRow+1; i++)
{
//Grab the values for LocationCodes
var siteCo = shLog.getRange([i],[12]).getValue();
//Enter formula
if(siteCo = ""){
siteCo.setFormula('=if(E'+[i]+'="08 - Maintenance Request System",LocationCodes!$E,vlookup(D'+[i]+',LocationCodes!$D:$E,2,false))');
}
}
}
您不能将方法 setFormula 应用于值,而是应用于范围。在你的方法上改变这个:
var siteCo = shLog.getRange([i],[12]);
if(siteCo.getValue() == ""){
siteCo.setFormula('=if(E'+[i]+'="08 - Maintenance Request System",LocationCodes!$E,vlookup(D'+[i]+',LocationCodes!$D:$E,2,false))');
}
我已将这个小脚本放在一起以将 if(vlookup) 公式插入到电子表格中,但即使它是 运行 它也没有在电子表格中插入任何内容。谁能提出我遗漏或忽略的建议?
或者有没有更简单的方法来使用数组?我还很新,所以不确定如何成功执行。
function idSiteCoordinator(){
var SS = SpreadsheetApp.getActiveSpreadsheet();
var shLog = SS.getSheetByName("LOG");
//declare how many rows to interrogate (to the last row)
var lastRow = shLog.getLastRow();
var startRow = 2;
for (var i=startRow; i<lastRow+1; i++)
{
//Grab the values for LocationCodes
var siteCo = shLog.getRange([i],[12]).getValue();
//Enter formula
if(siteCo = ""){
siteCo.setFormula('=if(E'+[i]+'="08 - Maintenance Request System",LocationCodes!$E,vlookup(D'+[i]+',LocationCodes!$D:$E,2,false))');
}
}
}
您不能将方法 setFormula 应用于值,而是应用于范围。在你的方法上改变这个:
var siteCo = shLog.getRange([i],[12]);
if(siteCo.getValue() == ""){
siteCo.setFormula('=if(E'+[i]+'="08 - Maintenance Request System",LocationCodes!$E,vlookup(D'+[i]+',LocationCodes!$D:$E,2,false))');
}