How to use VLookup to get multiple values

How to use VLookup to get multiple values automatically using VBA. Because the standard VLookup function can access only one column at a time, we generally can extract information from one column to the right of the lookup value.

Watch the training video before studying the recorded and modified code and the hand-crafted VBA code:


Recorded and modified VBA code using COLUMNS property:

Sub getMultipleValuesWithVlookup()
ActiveCell.Formula = “=VLOOKUP($C$3,$C$5:$I$9,columns($C2:D2),0)”
Range(“D3”).AutoFill Destination:=Range(“D3:I3”), Type:=xlFillDefault
End Sub

Handcrafted looping process to get multiple values with VLookup:

Sub multiVlookupLoop()
Dim r As Long, c As Long, col_index As Long, lastColumn As Long
lastColumn = Cells.Find(What:=”*”, After:=Range(“A1”), LookAt:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, MatchCase:=False).Column
‘MsgBox lastColumn
r = 3
col_index = 2
For c = 4 To lastColumn
    Cells(r, c).Value = Application.WorksheetFunction.VLookup(Range(“C3”), Range(“C5:I9”), col_index, False)
col_index = col_index + 1
Next c
End Sub
Further Reading:

Power Excel with MrExcel – 2017 Edition: Master Pivot Tables, Subtotals, Visualizations, VLOOKUP, Power BI and Data Analysis