title: VBA: VLookUp Multiple Results
body: <p>I require a little help with some code.</p>
  
  <p>I am trying to perform a VLookup, and has the data displayed in columns O, P and Q.</p>
  
  <p>What i am trying to do is loop though sheet("Global") column A starting at row 3 until last used row. It needs to match data in sheet("Details") in column A starting at row 2. </p>
  
  <p>So when it finds a matching value, it will display the results from "Details" C2 in "Global" O2, "Details" I2 in "Global" P2 and "Details" G2 in "Global" Q2.</p>
  
  <p>It then needs to loop though "Global" matching and copying all data. If no match is found the display "NA!".</p>
  
  <p>The last thing I need it to do is to delete all rows in Global where a match was not found.</p>
  
  <p>The code I have below does what I need, the only problem is that it is incredibly slow, taking minutes to loop though 800 rows, sometimes even longer!!</p>
  
  <p>Is there another way to do this, that will run smoother and faster?</p>
  
  <p>Any help is appreciated!!</p>
  
  <p>Thank You</p>
  
  <pre><code>`Private Sub btnVlookUp_Click()
  Dim i, j, lastG, lastD As Long
  
  ' find last row
  lastG = Sheets("Global").Cells(Rows.Count, "B").End(xlUp).Row
  lastD = Sheets("Details").Cells(Rows.Count, "A").End(xlUp).Row
  
  ' loop over values in "Global"
  For i = 3 To lastG
      lookupVal = Sheets("Global").Cells(i, "B") ' value to find
  
      ' loop over values in "details"
      For j = 2 To lastD
          currVal = Sheets("Details").Cells(j, "A")
  
          If lookupVal = currVal Then
              Sheets("Global").Cells(i, "O") = Sheets("Details").Cells(j, "C")
              Sheets("Global").Cells(i, "P") = Sheets("Details").Cells(j, "I")
              Sheets("Global").Cells(i, "Q") = Sheets("Details").Cells(j, "G")
              ' mark the row
              Sheets("Details").Cells(j, "Z") = "marked"
  
          End If
      Next j
  Next i
  
  ' loop over rows in "details" and delete rows which have not been marked
  For j = 2 To lastD
      If Sheets("Details").Cells(j, "Z") &lt;&gt; "marked" Then
          ' delete unmarked rows
          Sheets("Details").Cells(j, "A").EntireRow.Delete
          If Sheets("Details").Cells(j, "B") &lt;&gt; "" Then
              j = j - 1 ' revert iterator so it doesn't skip rows
          End If
      Else:
          ' remove the mark
          Sheets("Details").Cells(j, "Z") = ""
      End If
  Next j
  End Sub`
  </code></pre>