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()
Range(“D3”).Select
ActiveCell.Formula = “=VLOOKUP($C$3,$C$5:$I$9,columns($C2:D2),0)”
Range(“D3”).AutoFill Destination:=Range(“D3:I3”), Type:=xlFillDefault
Range(“D3:I3”).Select
Range(“A3”).Select
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

2 thoughts on “How to use VLookup to get multiple values

  1. Pingback: How to Print Non Blank Pay Slips | Excel VBA Training Online

  2. Mike Thompson

    Great Video learned lots… but I have a question how can I add additional names under C3 so I can create a sheet with more than one name being used at a time

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *