In order to optimize my code, I'm trying to do the batch updates. Instead of calling setValues() on the loop, I want to store the data in an array, then do an setValues() once after the loop. However, I can't make it work:
var tempValuesArr= [];
var ctr = 0;
for ....{
//there is only one row needed for every second sheet, get the data at the 2nd
//row with 6 columns
var secondSheetRange = secondSheet.getRange(2, 1, 1, 6);
tempValuesArr.push(secondSheetRange.getValues());
ctr++;
}
//finally, copy these tempValues at another sheet, starting at second row
var anotherSheetRange = anotherSheet.getRange(2, 1, ctr, 6);
anotherSheetRange .setValues(tempValuesArr);
Here's the error I'm getting:
Incorrect range width, was 1 but should be 6
Thanks!