Tuesday, January 28, 2014

VLOOKUP function to get multiple match in a row

Steps to insert new module
1. open workbook.
2. Press alt+f11 TO GO TO VBE(visual basic editor).
3. Insert new module.
4. copy code to new module.

Function Multiple_Vlookup(lookup_value As Range, tbl As Range, col_index_num As Integer)
Dim r As Single, strng As String
Application.Volatile
strng = ""
For r = 1 To tbl.Rows.Count
    If lookup_value = tbl.Cells(r, 1) Then
        strng = strng & tbl.Cells(r, col_index_num) & " ,"
        
    End If
Next r
    Multiple_Vlookup = Left(strng, Len(strng) - 2)
End Function

save this workbook as an add-in file(xla or xlam).Make add-in available via excel add-in command bar.

Application of function: =Multiple_vlookup(lookup_value,tbl,col_index_num)

This function is same as normal vlookup function hence should be applied in same manner.
Multiple_vlookup

No comments:

Post a Comment