0

I have one data sheet with codes as csv Other reference data sheet with each code and name it corresponds to.

How do I vlookup multiple items and return corresponding names Cell B2 is where I want to vlookup and get Test,Abc

enter image description here

enter image description here

6
  • 1
    what version do you have? Commented Sep 2, 2020 at 17:09
  • If you do not have TEXTJOIN as a formula option this will require vba. Commented Sep 2, 2020 at 17:09
  • Office Pro+ 2016 Commented Sep 2, 2020 at 17:10
  • You will need vba. Commented Sep 2, 2020 at 17:11
  • Can you show where the Names "Test" and "Abc" would be in the first screenshot? Would they also be comma separated in B2? Or...? Commented Sep 2, 2020 at 17:11

1 Answer 1

3

If one has TEXTJOIN use:

=TEXTJOIN(", ",TRUE,IFERROR(VLOOKUP(FILTERXML("<a><b>"&SUBSTITUTE(A2,",","</b><b>")&"</b></a>","//b"),D:E,2,FALSE),""))

Depending on one's version this may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.

enter image description here

If one does not have text join, put this code in a module attached to the workbook.

Function TEXTJOIN(delim As String, skipblank As Boolean, arr)
    Dim d As Long
    Dim c As Long
    Dim arr2()
    Dim t As Long, y As Long
    t = -1
    y = -1
    If TypeName(arr) = "Range" Then
        arr2 = arr.Value
    Else
        arr2 = arr
    End If
    On Error Resume Next
    t = UBound(arr2, 2)
    y = UBound(arr2, 1)
    On Error GoTo 0

    If t >= 0 And y >= 0 Then
        For c = LBound(arr2, 1) To UBound(arr2, 1)
            For d = LBound(arr2, 1) To UBound(arr2, 2)
                If arr2(c, d) <> "" Or Not skipblank Then
                    TEXTJOIN = TEXTJOIN & arr2(c, d) & delim
                End If
            Next d
        Next c
    Else
        For c = LBound(arr2) To UBound(arr2)
            If arr2(c) <> "" Or Not skipblank Then
                TEXTJOIN = TEXTJOIN & arr2(c) & delim
            End If
        Next c
    End If
    TEXTJOIN = Left(TEXTJOIN, Len(TEXTJOIN) - Len(delim))
End Function

Then use the formula:

=TEXTJOIN(", ",TRUE,LOOKUP(FILTERXML("<a><b>"&SUBSTITUTE(A2,",","</b><b>")&"</b></a>","//b"),D:D,E:E))

using Ctrl-Shift-Enter to confirm. Also make sure the lookup table is sorted ascending on the lookup column.

Sign up to request clarification or add additional context in comments.

11 Comments

Apparently Excel 2016 Pro + doesn't have this unless you have office 365. I tried in Office with no luck. What are <a><b> for? Do they need to change if my data is column K and I am trying to get values in column L next to it?
Which is why I provided the vba code to mimic the TEXTJOIN function. Put that code in a module attached to the workbook and you can then use the TEXTJOIN function.
Looks like FILTERXML is not available for web so that might be it.I will go VBA route thanks
Can you share the vba excel somewhere?
See edit, had to break out my 2016 version to trouble shoot. the problem was the formula not the vba.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.