title: Retrieve row from a table (with a specific value) and insert specific row to a new sheet
body: <p>I'm new and couldn't figured it out. This is the Scenario</p>
  
  <p>1)I have one table where i have 3 column, one of those columns has a category value.</p>
  
  <p>2)I'm working on a script where I select the range from the table and look up for that value in that specific column.</p>
  
  <p>3)If the row has that value im looking for, i want to copy the whole row of the table and paste it on a new spread sheet.</p>
  
  <blockquote>
    <p>function myFunction() {</p>
    
    <p>var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");</p>
    
    <p>var range =sheet.getRange('B1:B35');</p>
    
    <p>var destination = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet3");</p>
    
    <p>var verduras ='verduras';</p>
    
    <p>var rule = SpreadsheetApp.newDataValidation().requireTextEqualTo('Category').copy();</p>
    
    <p>range.setDataValidation(rule);
    range.copyValuesToRange(destination, 1, 2, 1, 2);</p>
    
    <p>}</p>
  </blockquote>
  
  <p>SOLUTION:</p>
  
  <pre><code>function myFunction() {
  
    var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("TableWithInformation");
    var columnToSearch = 2; // B column 
    var lastrow = sheet.getLastRow();
    Logger.log(sheet.getLastRow());
    var range =sheet.getRange(1,columnToSearch,sheet.getLastRow(),columnToSearch);
    var destination = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Report");
    var values = range.getValues();
  
    //Destination  
    var numberOfColumns = 3;
    var numberOfRows = 1 ;
    var startColumn = 1;
    var startRow = 2;
  
    // equivalent to destination.getRange('A1:C3');     
    var count = 0
    var destRow = destination.getLastRow()+1
    for(var i=0;i&lt;values.length;i++){
      Logger.log("i is now: " +i);
      Logger.log("Current row value: " +values[i][0]) 
  
      if(values[i][0] == 'Category'){
        Logger.log("*** Value found in cloumn: " +values[i][0] +"**** \n Count: " +i);
        count++;
  
        var rangeToCopy = sheet.getRange((i+1), 1,numberOfRows,numberOfColumns);
  
        var destinationRange = destination.getRange(destRow, startColumn,numberOfRows,numberOfColumns);
        destRow++;
        Logger.log("Next Destination row: " + destRow);
        rangeToCopy.copyTo(destinationRange);
  
  
      }
    }
  
  }
  </code></pre>