title: Excel VBA - Comparing rows in same column
body: <p>I am new to excel VBA and I have a task I need to complete using VBA. I am looking to compare values in the same column. I want to start the comparison with the last row and move up. The criteria for filtering is if the % difference between the current and last number is greater than 3% then copy and paste the value to another row. Once a value is copied and pasted, values in the data should be compared to the previous copied and pasted value when checking for the 3% difference. Example below. Thanks in advance.</p>
  
  <p>For example if my data range is shown below</p>
  
  <pre><code>1100
  1285
  1290
  3005
  1500
  2020
  2030
  2040
  2050
  2060
  2070
  2080
  2100
  2500
  3000
  </code></pre>
  
  <p>This should be my result:</p>
  
  <pre><code>1100
  1290 
  1500 
  2030 
  2100 
  2500 
  3000
  </code></pre>
  
  <p>The results I have right now have 3005 in there (the difference between 3000 and 3005 is less than 3% percent (3005/3000) thus 3005 should not be in the list), when it should not be in the list.</p>
  
  <pre><code>1100
  1290
  3005
  1500
  2030
  2100
  2500
  3000
  </code></pre>
  
  <p>This is the code I have at the moment. Thanks in advance.</p>
  
  <pre><code>Sub main2()
  
  Dim row_a As Long
  Dim row_b As Long
  Dim l_2
  
  row_b = Range("D5000").End(xlUp).Row
  Cells(row_b, "d").Copy Cells(row_b, "P")
  
  l_2 = row_b - 1
  
  For i = row_b To 3 Step -1
      a = Cells(row_b, "d").Value
      For j = l_2 To 3 Step -1
          If a / Cells(j, "d") &lt;= 0.97 Or a / Cells(j, "d") &gt;= 1.03 Then
              Cells(j, "d").Copy Cells(j, "p")
              a = Cells(j, "d").Value
          End If
      Next j
  Next i
  
  End Sub
  </code></pre>