title: Google app script to copy column values to a different sheet
body: <p>I am trying to write a google app script so I can copy a few columns (C and D) from my main report sheet to a different sheet, based on the value of column M if that's equal to 0. </p>
  
  <p>As shown in the pic below: 
  <img src="https://i.stack.imgur.com/OtBBO.png" alt="enter image description here"></p>
  
  <p>So I want to copy the "Name" and "Variety" columns into another sheet where the "Germination %" column is 0.</p>
  
  <p>It can be a time based trigger, that runs after every 2 hours or onEdit also. I was trying to make it a script using OnEdit, as shown below: </p>
  
  <pre><code>    function onEdit( e ){
        var sheetFrom = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("germination");
        var sheetTo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("watering");
  
          var data = sheetFrom.getDataRange().getValues();
          var target = new Array();// this is a new array to collect data
          for(n=0;n&lt;data.length;++n){ // iterate in the array, row by row
            if (data[n][12]=="0"){ // if condition is true copy the whole row to target
              target.push(data[n]);// copy the whole row
             }//if
          }//for
  
          //Paste to another sheet from first cell onwards
          sheetTo.getRange(1,1,target.length,2).setValues(target);
  }
  </code></pre>
  
  <p>But I am getting errors on this "Incorrect range width, was 15 but should be 2 (line 25, file "Code")" </p>
  
  <p>Line 25 is "sheetTo.getRange(1,1,target.length,2).setValues(target)"</p>
  
  <p>Thanks in advance.</p>