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

Published by

Dinesh Kumar Takyar

Welcome to exceltrainingvideos.com! My aim is to help you learn MS Excel including VBA. I always felt that a good way to learn something was to find solutions to problems in that domain. That is why I share these Excel videos with you. Mostly these are questions asked during my corporate training sessions. I've been training individuals and companies in computers since 1991. I did my B. Sc. (Vordiplom), M. Sc. (Diplom) and Ph.D. (Dr. rer. nat.) from Hamburg, Germany. The best thing about solving some of my visitor's questions is that I also gain new insights. For more Excel VBA solutions you may like to visit my YouTube channel: http://youtube.com/familycomputerclub For a structured Excel VBA training course online you can visit: https://www.youtube.com/excelvbaonline

3 thoughts on “How to use VLookup to get multiple values”

  1. 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

  2. SIR
    CAN YOU HELP ME WITH THIS: HOW TO GET MATCHES WITH EMPTY CELLS IN A ROW
    blend MEK MAAK CARB MILK CHLOR THF
    ABC120 10 50 40
    ABC150 50 50
    ABC200 12 13 75
    ABC210 40 40 20

    BLEND NAME
    ABC150 MAAK
    MILK

Leave a Reply

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