title: I need to copy data from 3 sheets to another master sheet in same spreadsheet
body: <p>I have written a code for this but getting an error</p>
  
  <p><code>The coordinates or dimensions of the range are invalid. (line 44)</code></p>
  
  <p>Code:   </p>
  
  <pre><code>function updateMaster() {
  var repArray  = new Array();
   var ss        = SpreadsheetApp.getActiveSpreadsheet();
   var allSheets = ss.getSheets();
   // build array of all sheets
   for (i in allSheets) {                              
     if ((allSheets[i].getName()).match(/.*?\-Rep$/))
        {repArray.push(allSheets[i].getName());}
   }
  
   // store all sheets in array
   var sheetArray = [];   
   // loop through all rep sheets                             
   for (var j in repArray) {       
     // get each sheet                    
     var tempSheet  = ss.getSheetByName(repArray[j]);  
         // get sheet data
     var dataRange  = tempSheet.getDataRange().getValues(); 
     // remove the first header row
     dataRange.splice(parseInt(0), 1);                 
         // append sheet data to array
     var sheetArray = sheetArray.concat(dataRange);    
   }
  
   // Time to update the master sheet
   var mSheet    = ss.getSheetByName("summary");        
   // save top header row
   var headerRow = mSheet.getRange(1,1,1,12).getValues(); 
   // clear the whole sheet
   mSheet.clear({contentsOnly:true});                 
   // put back the header row 
   mSheet.getRange(1, 1, 1, 12).setValues(headerRow); 
  </code></pre>
  
  <p>This is where i am getting error while writing to master sheet:</p>
  
  <pre><code> // write to the Master sheet via the array 
   mSheet.getRange(2, 1, sheetArray.length, 12).setValues(sheetArray);
    // force spreadsheet updates
   SpreadsheetApp.flush();                   
   // pause (1,000 milliseconds = 1 second)          
   Utilities.sleep("200");                             
  
   // delete empty rows at bottom
   var last = mSheet.getLastRow();                     
   var max  = mSheet.getMaxRows();
   if (last !== max) {mSheet.deleteRows(last+1,max-last);}
  
  }
  </code></pre>
  
  <p>I am not able to figure out the error.</p>