title: Lookup operation gives no result
body: <p>The following code to matches a value from sheet A with sheet B, in a manner similar to Excel's <code>VLOOKUP</code> function. </p>
  
  <p>The code runs without error but I get no result in the cells. How can I fix this?</p>
  
  <pre><code>Sub LoopTem()
  
  Dim ws As Worksheet
  Dim ws1 As Worksheet
  Dim i As Integer
  Dim r As Integer
  Dim lastRow1 As Integer
  Dim lastRow2 As Integer
  
  Set ws = Worksheets("Proactive Template")
  Set ws2 = Worksheets("To")
  
  lastRow1 = ws.Range("Q" &amp; Rows.Count).End(xlUp).Row
  lastRow2 = ws2.Range("Q" &amp; Rows.Count).End(xlUp).Row
  
  For i = 2 To lastRow1
      For r = 2 To lastRow2
          If ws.Cells(i, 18) = ws2.Cells(r, 17) Then
             ws.Cells(i, 20) = ws2.Cells(r, 19)
          Else
             ws.Cells(i, 20) = ""
          End If
      Next r
  
  Next i
  
  
  End Sub
  </code></pre>