title: If cell value the same as above, then
body: <p>I am trying to check if the value in a cell in Column B is the same as a cell in Column B in another row, Y places lower/higher. Y being a value in cell &quot;A8&quot;.</p>
  <p>IF the values are the same then the value in Column P of the same row has to get the same value as in Column R of the same row.<br />
  ELSE Column Q of that row has to get the same value as in Colom R of the same row.</p>
  <p>In the schematic below, Y=2, so column B1 check 2 places lower B3 is the same so data in R1 should also be in P1.<br />
  Continuing the same idea B4 compared with B6 does not have the same value so the Q4 should have the same value as R4.</p>
  <p>Representation of the input</p>
  <pre><code>ColumnA ColumnB ColumnP ColumnQ Column R
             1                       x         
             2                       x        
     2       1                       x        
             2                       x    
             30                      x      
             40                      x         
             50                      x
             60                      x  
  </code></pre>
  <p>Desired result</p>
  <pre><code>ColumnA ColumnB ColumnP ColumnQ ColumnR
             1       x               x         
             2       x               x        
     2       1       x               x        
             2       x               x    
             30              x       x      
             40              x       x         
             60              x       x
  </code></pre>
  <p>I tried multiple things. The last I tried below.</p>
  <pre class="lang-vb prettyprint-override"><code>For iRow = Range(&quot;B3:B2502&quot;).Rows.Count To 1 Step -1
      If Cells(iRow + 2, 2).Value = Cells(iRow + Y, 2) Then
          Cells(iRow + 2, 15).Value = Cells(iRow + 2, 17)
      Else
          Cells(iRow + 2, 16).Value = Cells(iRow + 2, 17)
      End If
  Next
      
  End Sub
  </code></pre>
  <p>And some variations with ranges.</p>