0

I have a for loop that we're trying to run that identifies the last row on another sheet, and populates a VLOOKUP in the cell next to it. For some reason I keep getting a variable error. Here's the code:

for (var c = 5; c < lstRow; c++) {
  var vlookupCell = "=VLOOKUP('"+sheet2.getRange(c,7).getValue()+"','"+NewSheetNm+"'!B:C,2,0)";
  sheet2.getRange(c,1).setValue(vlookupCell);
  CurrRow=CurrRow+1;
}

The variable "NewSheetNm" lives in the beginning of this function. This is just the last part of this current function. Anyone have any ideas why this won't work?

4

1 回答 1

2

产生了什么错误?

最好的方法是使用setFormula(formula)方法:

...
sheet2.getRange(c, 1).setFormula(vlookupCell);
...
于 2013-10-15T20:16:06.940 回答