Question

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?

Was it helpful?

Solution

What error is being generated?

The best would be to use the method setFormula(formula):

...
sheet2.getRange(c, 1).setFormula(vlookupCell);
...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top