title: VBA: How to compare values of changing cells in a column with another dynamic range?
body: <p><a href="https://i.stack.imgur.com/ZvRpc.png" rel="nofollow noreferrer">I have a list of 500 orders</a>, each with a product code. I don't know how many different product codes exist (there are multiple orders for the same product code). I need to write a Macro code to find all the existing product codes and paste them in the column L.</p>
  
  <p>The first product code will be pasted in column L as is. Now,  as this continues I want the next product code from column C to be checked with all the values that have been entered in column L, i.e., for eg, if A01 has already been pasted in column L then when A01 occurs the next time in Column C, I don't want it to be pasted in Column L.</p>
  
  <p>What I mean is I want to find all the unique product codes I have.
  I have accomplished this by recording a data filter (Ascending) marco but I want to know how this can be done by writing my own code.
  Thanks a lot in advance! :)</p>
  
  <pre><code>Sub try()
  
      Dim j as long
  
      Dim i As Long, lastrow As Long
  
  
  
      lastrow = Workbooks("A.xlsx").Worksheets("Sheet1").Range("A1048576").End(xlUp).Row
      On Error GoTo 0
  
      Range("C2").Select
      Selection.Copy Workbooks("A.xlsx").Worksheets("Sheet1").Range("L2")
  
      For i = 3 to lastrow
  
      j = Workbooks("A.xlsx").Worksheets("Sheet1").Range("L1048576").End(xlUp).Row + 1
  
         If Range("C" &amp; i).value &lt;&gt; Range("L2:L" &amp; j - 1).value Then 'Here's what I don't know how to write
  
         Range("C" &amp; i).select
  
         Selection.Copy Workbooks("A.xlsx").Worksheets("Sheet1").Range("L" &amp; j)
  
      Next i
  
  End Sub
  </code></pre>