title: Google Spreadsheet Script - a more direct way of dumping array to sheet?
body: <p>Just wondering if anyone could give me some pointers on a more direct way of replacing / overwrite a column on the SpreadSheet with that from a 2D array (memory).</p>
  
  <p>Currently, the below code writes value to cell by scrolling down row-by-row via a "for" loop. This was fine but now that the sheet's grown over 7k rows, this script has approach execution time limit.</p>
  
  <p>The process of saving the entire sheet to memory array and calculations took very little time, it's the for loop that calls the sheet cell-by-cell that seems to take forever.</p>
  
  <p>There must be a more direct way of a replacing an entire column rather than scrolling cell by cell down the column to update values.  </p>
  
  <p>Any pointers would be much appreciated, please forgive my ignorance, I'm only very new to scripting.</p>
  
  <p>Regards
  M</p>
  
  <pre><code>   function UnitPrice() {
        var range = Stocklist.getRange(1, 1, LastRow, LastColumn).getValues();  
  
        for (var i=1; i &lt; (LastRow); i++){
          var PurposeArray = range[i][PurposeCol-1]; 
          var ListedArray = range[i][ListedCol-1];
          var QtyArray = range[i][QtyCol-1];
          var CostArray = range[i][Cost$Col-1];
          var Unit$Array = range[i][Unit$Col-1]; 
          var PremiumArray = range[i][PremiumCol-1];
  
          if (QtyArray!="0" &amp;&amp; QtyArray!=""){
            range[i][Unit$Col-1] = CostArray*(1+PremiumArray)/QtyArray;
          } else{
            range[i][Unit$Col-1] = "";
          } 
  
          if (ListedArray!=""&amp;&amp;PurposeArray=="" ){           
              range[i][PurposeCol-1] = "Stock";
          }
        }
  
  
        //update spreadsheet's column "Unit$Col" with values from column 25 of 'range' array.
        for (var j=1; j &lt; LastRow; j++){
          Stocklist.getRange(j+1, Unit$Col).setValue(range[j][Unit$Col-1]);
          Stocklist.getRange(j+1, PurposeCol).setValue(range[j][PurposeCol-1]); 
        }
      }
  </code></pre>