title: Excel compare two columns from one sheet copy entire row on match to new sheet
body: <p>I am looking for VBA code that will do the following:</p>
  
  <ul>
  <li>On Sheet 1, starting from A2, scroll down and compare each cell, one at a time, with each cell in the second column, starting with B2.</li>
  <li>If there is a match, copy entire row of matching entry in second column into Sheet 2</li>
  <li>If, after scrolling through column B, there were no matches, insert a blank row in Sheet 2</li>
  </ul>
  
  <p>Here is some pseudocode that may clarify what I'm looking for:</p>
  
  <p>For each cell in columnA<br />
  Traverse each cell in columnB<br />
  If current cell value in columnA matches current cell value in columnB<br />
  Copy the entire row at the current columnB position<br />
  If we have traversed the entire columnB and have not found a match<br />
  Insert a blank row in sheet2</p>
  
  <p>Here is the best I could come up with, but I am not well-versed in manipulating excel sheets:</p>
  
  <pre><code>Sub rowContent()
  
  Dim isMatch As Boolean
  isMatch = False
  
  Dim newSheetPos As Integer
  newSheetPos = 1
  
  Dim numRows As Integer
  numRows = 591
  
  Dim rowPos As Integer
  rowPos = 1
  
  For i = 1 To numRows 'Traverse columnA 
   For j = 1 To numRows 'Traverse columnB
      'Compare contents of cell in columnA to cell in ColumnB
      If Worksheets("Sheet1").Cells(i, 1) = Worksheets("Sheet1").Cells(j, 2) Then
          Worksheets("Sheet1").Cells(i, 1).Copy Worksheets("Sheet2").Cells(newSheetPos, 1)
          newSheetPos = newSheetPos + 1'prepare to copy into next row in Sheet2
          isMatch = True 
      End If
  
      j = j + 1 'increment j to continue traversing columnB
   Next
   'If we have traverse columnB without finding a match
   If Not (isMatch) Then 
          newSheetPos = newSheetPos + 1 'skip row in Sheet2 if no match was found
   End If
   isMatch = False
  Next
  End Sub
  </code></pre>
  
  <p>This code does not currently work.</p>
  
  <p>Many thanks for your kind help.</p>