How to copy only specific rows inside function instead of full row
<p>I have a function which I got from online and modded slightly for my own use.  Something I can not get working is how do I delete the full row and only copy over specific rows inside the function below.</p>

<p>I would like to be able to pass in variables to the function for each sheet and its corresponding columns to copy over.</p>

<p>ex. moveCompletedRows(type,whereToMoveType,[cell's to move]){}</p>

<pre><code>function moveCompletedRows(type,whereToMoveType) {

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('SortBot');
  var targetSheet = ss.getSheetByName(whereToMoveType);
  var val = sheet.getDataRange().getValues();
  var headers = val.shift();
  var arr = [], rowsToWriteBack = [];

  rowsToWriteBack.push(headers);

  val.forEach(function (r, i) {
    r[1] == type ? arr.push(r) : rowsToWriteBack.push(r)
  });

  if (arr.length &gt; 0) {
    targetSheet.getRange(targetSheet.getLastRow() + 1, 1, arr.length, arr[0].length)
    .setValues(arr);
    sheet.clear();
    sheet.getRange(1, 1, rowsToWriteBack.length, rowsToWriteBack[0].length)
    .clear()
    .setValues(rowsToWriteBack);
  }
}
</code></pre>

<p>Aside:
The reason my current setup needs to change is since my form is so large (multi section form) submits alot of columns (A-CH) and each entry only submits around 8 each (just in different columns), even with hiding columns, when I view the pages on a mobile device it freezes/crashes 50% of the time(I am not sure this will fully solve it as the sheet with many rows will still be on that master sheet, note that it will be blank). Which makes me question if just having a sheet with that many cells that is never viewed on a mobile device cause the sheet to load very slow?</p>

<p>Thanks</p>

<p><strong>Edit:</strong></p>

<p>Link to the Drive folder containing the form/sheet/ script</p>

<p><a href="https://drive.google.com/folderview?id=0B-7N8A7FPKw5V20yRVFQcmNZTlk&amp;usp=sharing" rel="nofollow">https://drive.google.com/folderview?id=0B-7N8A7FPKw5V20yRVFQcmNZTlk&amp;usp=sharing</a></p>

<p><strong>Edit2:</strong></p>

<p>Been trying to work on this the last few days and I have a secondary script I have semi working but part marked below is what I want to have working in the original formula</p>

<pre><code>function onEdit() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet2Copy = ss.getSheetByName('Actions');
  var targetSheet = ss.getSheetByName('Test');

  var data = sheet2Copy.getRange(1,1, sheet2Copy.getLastRow(), sheet2Copy.getLastColumn()).getValues();

  var dest = [];

  for (var i = 0; i &lt; data.length; i++ ) {

    Logger.log(data[i][12]);// just to check if the condition is true sometimes ;-)

    if (data[i][1] == "Action") {

      var rowsToWriteBack = []; // initialise intermediate array

      // GET THIS WORKING IN ABOVE FORMULA
      // Trying to select columns to put into new sheet.  Will eventually make the #'s variables passed into the formula to make it dynamic
      rowsToWriteBack.push(
        data[i][0],
        data[i][1],
        data[i][2],
        data[i][10],
        data[i][11],
        data[i][12],
        data[i][13]
      );// choose here the columns you want to add 

      dest.push(rowsToWriteBack);
    }
  } // here is the end of the for loop

  Logger.log(dest) ; // log the dest array instead

  if (dest.length &gt; 0 ) { // if something has been written in your array then batch write it to the dest. sheet
    targetSheet.getRange(targetSheet.getLastRow()+1,1,dest.length,dest[0].length).setValues(dest);
  }
}
</code></pre>