Hi there! Does anyone have a suggestion about improving the performance of this lookup? The code works but it take 9 minutes to run through 47,000 records. I technically don't need the message error running but I couldn't figure out how to get it to run without it. Is there another way I can run this code faster? Thanks in advance.
Sub VLookupStep1()
Dim Sh1, Sh2 As Worksheet
Dim MyRange As Range
Set Sh1 = ThisWorkbook.Sheets("Step1")
Set Sh2 = ThisWorkbook.Sheets("P21")
Set MyRange = Sh2.Range("B:C")
LastRow = Sh1.Range("C" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
On Error GoTo Error:
Sh1.Range("D" & i).Value = Application.WorksheetFunction.VLookup(Sh1.Range("C" & i), MyRange, 2, False)
Next i
Error:
Sh1.Range("D" & i).Value = "N/A"
Resume Next
End Sub
Sub VLookupStep1()
Dim Sh1, Sh2 As Worksheet
Dim MyRange As Range
Set Sh1 = ThisWorkbook.Sheets("Step1")
Set Sh2 = ThisWorkbook.Sheets("P21")
Set MyRange = Sh2.Range("B:C")
LastRow = Sh1.Range("C" & Rows.Count).End(xlUp).Row
For i = 2 To LastRow
On Error GoTo Error:
Sh1.Range("D" & i).Value = Application.WorksheetFunction.VLookup(Sh1.Range("C" & i), MyRange, 2, False)
Next i
Error:
Sh1.Range("D" & i).Value = "N/A"
Resume Next
End Sub