Copy this code to a standard module (in excel press Alt + F11 to open the editor, then insert > module from the editor menu).
Option Explicit
Public Function MLOOKUP(mRef As String, mRng As Range, mCol As Long) As String
Dim mRefArr, a As Long, tmpStr As String
If InStr(mRef, ",") Then
mRefArr = Split(mRef, ",")
For a = 0 To UBound(mRefArr)
tmpStr = tmpStr & Application.WorksheetFunction.VLookup(Trim(mRefArr(a)), mRng, mCol, 0) & ", "
Next
MLOOKUP = Left(tmpStr, Len(tmpStr) - 2)
Else
MLOOKUP = Application.WorksheetFunction.VLookup(mRef, mRng, mCol, 0)
End If
End Function
Then in Q2 use =MLOOKUP(P2,TOM!$A$4:$B$13,2)
Formula entry is the same as VLOOKUP, but without the last optional TRUE /FALSE argument, I've fixed that to false / exact match within the code.
If no match is found the formula will return an error which can be suppressed in the usual way, i.e. =IFERROR(MLOOKUP(P2,TOM!$A$4:$B$13,2),"")
Where a cell contains multiple strings to lookup, i.e. P3 in the dummy file, the function will return the whole set as a single error.
Bookmarks