title: Google Script: Delete row if a value in it exists in another sheet
body: <p>I have a question with Google Scripting. I just started using Google Script this February so I  don't have deep understanding with it yet. Anyway my question is:</p>
  
  <p>Can I delete a row if certain values of it exist in another sheet? I tried several concepts I found in the internet but I was not able to come up with a working function.</p>
  
  <p>Here's the <a href="https://docs.google.com/spreadsheet/ccc?key=0AgvpJFmpMsvrdGlKVENpMGRNZ1lxWGc2ZEpGczNzN1E&amp;usp=sharing" rel="nofollow">Google Doc</a> for a detailed view.</p>
  
  <p>For example, in Sheet 1 I have two rows:</p>
  
  <hr>
  
  <p><em><strong>NAME | PLACE | AGE</em></strong></p>
  
  <p>Carl |  Florida | 45</p>
  
  <p>Mike |  Florida | 41</p>
  
  <hr>
  
  <p>And in Sheet 2:</p>
  
  <hr>
  
  <p><em><strong>NAME | PLACE | AGE</em></strong></p>
  
  <p>Mike |  Florida | 41</p>
  
  <hr>
  
  <p>The script should delete Mike Florida row in Sheet 1 since it has duplicate data in Sheet 2. So basically, if data in Sheet 2 exists in Sheet 1, it should be deleted in Sheet 1. But the tricky part is, I have to compare column 1 and column 2 only. Column 3 is not important. If column 1 and 2 in Sheet 2 have the same exact value in Sheet 1, it should be deleted in Sheet 1 and data in Sheet 2 should remain.</p>
  
  <p>I tried this <a href="https://developers.google.com/apps-script/articles/removing_duplicates" rel="nofollow">tutorial</a> in Google site but still I was not able to compare the two sheets and remove the duplicate data. </p>
  
  <p>Thank you so much. Any help/idea/advice will be greatly appreciated. :)</p>
  
  <p>+++++++++</p>
  
  <p>I just came up with a code now and used 2D Arrays Library. </p>
  
  <pre><code>function deleteRowInSheet1() { 
     var s1 = SpreadsheetApp.openById("COPY SPREADSHEET ID HERE").getSheetByName('Sheet1');
     var s2 = SpreadsheetApp.openById("COPY SPREADSHEET ID HERE").getSheetByName('Sheet2'); 
     var values1 = s1.getDataRange().getValues();
     var values2 = s2.getDataRange().getValues();
    // Check if Mike exists in SS1.
    if (ArrayLib.find(values2, 0, 'Mike') != -1) {
      for( var row = values1.length -1; row &gt;= 0; --row ) {
        if (values1[row][0] == 'Mike')
        s1.deleteRow(parseInt(row)+1);
      }
    }
  }
  </code></pre>
  
  <p>But, this code only gets specific value which is Mike. If row Mike exists in Sheet 2, row Mike in Sheet 1 will be deleted too. I tried modifying the code more to compare the two values from the two different sheets but I can't seem to make it work. </p>