title: google apps script - batch setValues() on Sheet
body: <p>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:</p>
  
  <pre><code>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);  
  </code></pre>
  
  <p>Here's the error I'm getting:</p>
  
  <blockquote>
    <p>Incorrect range width, was 1 but should be 6</p>
  </blockquote>
  
  <p>Thanks!</p>