multi match vlookup

Get VLOOKUP Multiple Matches – Multi INDEX MATCH in Excel

The Excel VLOOKUP function by default allows you to find only a single match and will return the corresponding row of a selected column value. What if you want to find VLOOKUP multiple matches, not just the first one? In this post let us explore this more complicated scenario. Instead of VLOOKUP however we will use INDEX and MATCH.

Using the MATCH Function in Excel

To find the first MATCH of the “A” value in column B:B we use the following formula as shown on the image below:


See the scenario below:
Get single Excel MATCH

Finding multiple matches in Excel

Now say we want to find all matches of “A” in column B:B as seen below.
Get VLOOKUP Multiple Matches in Excel
Below the formulas in cells E2-E4. In E2 we find the corresponding row of the first “A”, then in subsequenty (E3-E4) we look for the rows of the next found “A”. You can drag this formula down as much times as needed.


'E3 (drag this down)

'E4 (dragged from E3)

VLOOKUP Multiple Matches

To do a multiple match VLOOKUP we simply need to expand on the above Multiple MATCH example and add the INDEX function like so:

'E4 (simply drag the E3 formula down)

Using VBA to do a VLOOKUP Multi Match

In case you want a more sophisticated approach to doing a multi match INDEX MATCH / VLOOKUP you can also use the VBA Dictionary to record all instances of all lookup values along with selected columns. A simple version of this approach can be found in my post about using VLOOKUP in VBA. Below, however, I expanded this example by using a VBA Collection inside the VBA Dictionary to store value associated with each match of every lookup value (basically creating a very simply tree-like structure).

Based on the “A1:B10” table above the VBA code below will create my dictionary dict object.

Dim dict As Object, col As Collection, item As Variant
    Set dict = CreateObject("Scripting.Dictionary")
    'Column B:B has my lookup values
    For Each r In Range("B:B").SpecialCells(xlCellTypeConstants)
        'Omit row with headers
        If r.Row = 1 Then GoTo NextR
        If dict.Exists(r.Value) Then
            Set col = dict(r.Value)
            Set col = New Collection
            'Column A:A has the values I want to find for each lookup
            Call dict.Add(r.Value, col)
        End If
        col.Add Range("A" & r.Row)
    Next r

After creating the dictionary I can now print all values from column “A:A” for any value of column “B:B”:

For Each item In dict("A")
   Debug.Print item
Next item