i need make this macro more effective and faster. My solution is very, very slow. There can be over 100k rows
Sub VlookupPOR()
Dim PorWs As Worksheet, InDataBodyWs As Worksheet
Dim PorLastRow As Long, InDataBodyLastRow As Long, x As Long
Dim dataRng As Range
Set PorWs = ThisWorkbook.Worksheets("POR")
Set InDataBodyWs = ThisWorkbook.Worksheets("InDataBody")
PorLastRow = PorWs.Range("A" & Rows.Count).End(xlUp).Row
InDataBodyLastRow = InDataBodyWs.Range("H" & Rows.Count).End(xlUp).Row
Set dataRng = InDataBodyWs.Range("H4:AR" & InDataBodyLastRow)
For x = 2 To PorLastRow
On Error Resume Next
PorWs.Range("L" & x).Value = Application.WorksheetFunction.VLookup( _
PorWs.Range("G" & x).Value, dataRng, 5, False) 'LastName
PorWs.Range("N" & x).Value = Application.WorksheetFunction.VLookup( _
PorWs.Range("G" & x).Value, dataRng, 7, False) 'FirstName
PorWs.Range("O" & x).Value = Application.WorksheetFunction.VLookup( _
PorWs.Range("G" & x).Value, dataRng, 2, False) 'BirthNumber
PorWs.Range("K" & x).Value = Application.WorksheetFunction.VLookup( _
PorWs.Range("G" & x).Value, dataRng, 4, False) 'NativeLastName
PorWs.Range("J" & x).Value = Application.WorksheetFunction.VLookup( _
PorWs.Range("G" & x).Value, dataRng, 16, False) 'legalPersonName
PorWs.Range("H" & x).Value = Application.WorksheetFunction.VLookup( _
PorWs.Range("G" & x).Value, dataRng, 18, False) 'legalPersonBusinessId
PorWs.Range("I" & x).Value = Application.WorksheetFunction.VLookup( _
PorWs.Range("G" & x).Value, dataRng, 24, False) 'legalPersonBusinessId
Next x
End Sub
I need a vlookup for multiple columns from two sheets. I have only one identifier for everything and I need to add data from another sheet.
Can you help me?