当单元格具有逗号分隔值时如何使用 VLOOKUP 或 XLOOKUP
How to use a VLOOKUP or XLOOKUP when a cell has comma seperated values
我正在尝试查找单元格中每个值的 ID。我尝试使用 VLOOKUP,但当一个单元格具有多个值时它会失败。
在这种情况下,B2 将更新为 4,1
带有 IF 的 TEXTJOIN:
=TEXTJOIN(",",TRUE,IF(ISNUMBER(SEARCH(","&SUBSTITUTE('Item Details'!$A:$A," ","")&",",","&SUBSTITUTE(A2," ","")&",")),'Item Details'!$B:$B,""))
这将对查找的输出进行排序 table order
另一个选项是使用 XLOOKUP:
=TEXTJOIN(",",TRUE,XLOOKUP(FILTERXML("<a><b>"&SUBSTITUTE(A2,",","</b><b>")&"</b></a>","//b"),'Item Details'!A:A,'Item Details'!B:B,"",0))
使用 Office 365 将按输入排序。
试试这个用户定义的小函数:
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
我正在尝试查找单元格中每个值的 ID。我尝试使用 VLOOKUP,但当一个单元格具有多个值时它会失败。
在这种情况下,B2 将更新为 4,1
带有 IF 的 TEXTJOIN:
=TEXTJOIN(",",TRUE,IF(ISNUMBER(SEARCH(","&SUBSTITUTE('Item Details'!$A:$A," ","")&",",","&SUBSTITUTE(A2," ","")&",")),'Item Details'!$B:$B,""))
这将对查找的输出进行排序 table order
另一个选项是使用 XLOOKUP:
=TEXTJOIN(",",TRUE,XLOOKUP(FILTERXML("<a><b>"&SUBSTITUTE(A2,",","</b><b>")&"</b></a>","//b"),'Item Details'!A:A,'Item Details'!B:B,"",0))
使用 Office 365 将按输入排序。
试试这个用户定义的小函数:
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