title: Copy and Paste the Row based on condition in another Sheet
body: <p>I've been looking on this website and others for an answer but can't find anything relevant and was wondering if someone could help please.</p>
  <p>I've using <strong>Apps Script - Google Sheets</strong>.</p>
  <p>The main sheet was called &quot;M-Front&quot;. So it got quotation number with revision number. If new quotation, the revision will be zero. If we revise the quotation once, the revision number will be 1.</p>
  <p>For example, GE-2108-0271-Rev.0 is <strong>new</strong> quotation.
  If we revise once, it would be GE-2108-0271-Rev.1.</p>
  <p>I have other sheet called &quot;M-Items&quot;.</p>
  <p>Let say for GE-2108-0271-Rev.0, we have three rows for that quotation number represent three items for that quotation.</p>
  <p>My intention is , if new revision was made in &quot;M-Front&quot;. It will be GE-2108-0271-Rev.1. But how to detect the last row from &quot;M-Front&quot; quotation number and in &quot;M-Items&quot; we copy and paste the rows. In this case, 3 rows/items. and make the quotation in &quot;M-Items&quot; from GE-2108-0271-Rev.0 to GE-2108-0271-Rev.1.</p>
  <p><a href="https://i.stack.imgur.com/ibweO.png" rel="nofollow noreferrer">M-Front</a>
  <a href="https://i.stack.imgur.com/sAO7a.png" rel="nofollow noreferrer">M-Items</a></p>
  <p>The Script i've stuck</p>
  <pre><code>function CopyRange() {
  var sourcespread = SpreadsheetApp.openById('1Zgs1jzjIeaBpd5Ms7emQgxhVJBMtlEOlDNDfxlhSRiY'); //replace with source ID
    var sourcesheet = sourcespread.getSheetByName('M-Front'); //replace with source Sheet tab name
    var destspread = SpreadsheetApp.openById('1Zgs1jzjIeaBpd5Ms7emQgxhVJBMtlEOlDNDfxlhSRiY'); //replace with destination ID
    var destsheet = destspread.getSheetByName('M-Items'); //replace with destination Sheet tab name
    var testrange = sourcesheet.getRange('M:M').getLastRow;
    var testvalue = (testrange.getValues());
    var data = [];
    var j =[];
  
    for (i=0;i&lt;testvalue.length;i++) {
      if (testvalue[i] /= 0) {
      data.push.apply(data,sourcesheet.getRange('A:A').getValues());
    //Copy matched ROW numbers to j
      j.push(i);
  }  
  }
    //Copy data array to destination sheet
    destsheet.getRange(destsheet.getLastRow()+1,1,data.length,data[0].length).setValues(data);
  }
  
  </code></pre>