title: Google Sheets Script to Fill Down intermittent blanks in a column
body: <p>Column C has an ID in it that pertains to several rows, but only the first row has an ID in it.</p>
  
  <p>I need to copy that ID value to the blank cells beneath, until I hit a cell that has another value in it.</p>
  
  <p><img src="https://i.stack.imgur.com/WDFi0.jpg" alt="Picture of the spreadsheet"></p>
  
  <p>I have tried adapting this script but it hits a timeout error.</p>
  
  <pre><code>function myFunction() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getActiveSheet();
    var last = sheet.getLastRow();//how many times should I do this?
  
    for (i = 5528; i &lt; last; i++) { 
      var test = sheet.getRange(i, 1,1,1);
      //Logger.log(test);
    //looks to see if the cell is empty
      if (test.isBlank()) {
        var rewind = sheet.getRange(i-1, 1, 1, 1).getValues();//gets values from the row above
        sheet.getRange(i, 1, 1, 1).setValues(rewind);//sets the current range to the row above
      } 
  
    }
  }
  </code></pre>
  
  <p>i is set to a big number because every time it times out I have to start over!</p>
  
  <p>I have read that it would be better to bring in the column in an array, work on it, then put it back out to save a lot of time.</p>
  
  <p>I have tried to adapt this but can't get past the variable.</p>
  
  <p>Am I on the right track?  I would like to pretty up a solution for the future where I can pass a column or range and do the same thing.</p>
  
  <p>Here is my failing attempt:</p>
  
  <pre><code>function FillDown2() {
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheetByName("Sheet2");
    var tracts = sheet.getRange("C15:C").getValues();
    var allTractList = [];
    var title;
  
    for (var row = 0, var len = tracts.length; row &lt; len; row++) {
      if (tracts[row][0] != '') {
        //response = UrlFetchApp.fetch(tracts[row]);
        //doc = Xml.parse(response.getContentText(),true);
        title = tracts[row][0];
        //newValues.push([title]);  
        allTractList.push([title]);  
        Logger.log(title);
      } else allTractList.push([title]);
    }
  
    //Logger.log('newValues ' + newValues);
    Logger.log('allTractList ' + allTractList);
  
    // SET NEW COLUMN VALUES ALL AT ONCE!
    sheet.getRange("B15").offset(0, 0, allTractList.length).setValues(allTractList);
    return allTractList; 
  }
  </code></pre>