1

I'm trying to find the ID for each value in a cell. I tried using a VLOOKUP but it fails when a cell has more than one value.

In this scenario, B2 would be updated to 4,1

enter image description here

enter image description here

BigBen
  • 46,229
  • 7
  • 24
  • 40
Taco_Buffet
  • 227
  • 1
  • 2
  • 16

2 Answers2

4

TEXTJOIN with an IF:

=TEXTJOIN(",",TRUE,IF(ISNUMBER(SEARCH(","&SUBSTITUTE('Item Details'!$A$2:$A$6," ","")&",",","&SUBSTITUTE(A2," ","")&",")),'Item Details'!$B$2:$B$6,""))

This will order the output on the lookup table order

enter image description here

Another option is using XLOOKUP:

=TEXTJOIN(",",TRUE,XLOOKUP(FILTERXML("<a><b>"&SUBSTITUTE(A2,",","</b><b>")&"</b></a>","//b"),'Item Details'!A:A,'Item Details'!B:B,"",0))

with Office 365 which will order by the input.

enter image description here

Scott Craner
  • 148,073
  • 10
  • 49
  • 81
1

Give this small User Defined Function a try:

Public Function zlookup(v As Variant, rng As Range) As String
    Dim a, arr, r As Range
    
    arr = Split(v, ",")
    For Each a In arr
        Set r = rng.Columns(1).Find(What:=a)
        zlookup = zlookup & "," & r.Offset(0, 1).Value
    Next a
    zlookup = Mid(zlookup, 2)
End Function

enter image description here

Gary's Student
  • 95,722
  • 10
  • 59
  • 99