Loop - Match values in two columns in different worksheets, copy entire row to new worksheet if match
<p>I'm new in VBA coding, and would really appreciate some help solving this problem.</p>

<p>I need to do as follows:</p>

<ul>
<li>Compare every value in column G, Worksheet1, to the Unique values in column D, Worksheet2.</li>
<li>If a value matches, copy from that row values in column: C, G &amp; I</li>
<li>Paste every match into Worksheet3</li>
</ul>

<p>I've tried this so far:</p>

<pre><code>Sub test()

    Application.ScreenUpdating = False

    Dim rng1 As Range, rng2 As Range, rngName As Range, i As Integer, j As Integer

    For i = 1 To Sheets("Worksheet1").Range("G" &amp; Rows.Count).End(xlUp).Row
        Set rng1 = Sheets("Worksheet1").Range("G" &amp; i)

    For j = 1 To Sheets("Worksheet2").Range("D" &amp; Rows.Count).End(xlUp).Row
        Set rng2 = Sheets("Worksheet2").Range("D" &amp; j)

        Set rngName = Sheets("Worksheet1").Range("H" &amp; j)

        If rng1.Value = rng2.Value Then
        rngName.Copy Destination:=Worksheets("Worksheet3").Range("B" &amp; i)
        End If

        Set rng2 = Nothing
    Next j
    Set rng1 = Nothing
 Next i

End Sub
</code></pre>

<p>But it doesn't work.</p>