答案1
您可以尝试这样的 UDF:
Option Explicit
Option Compare Text
Function Magistry(Itemlist As Range, Inventory As Range, Attributes As Range)
On Error GoTo Catcher
Dim MyList As Variant, Powers As String, c As Variant, i As Long, n As Long
MyList = Split(Inventory, Chr(10))
n = 1
For Each c In Itemlist
For i = LBound(MyList) To UBound(MyList)
If MyList(i) = c And Attributes(c.Row, 1) <> vbNullString Then
If n = 1 Then
Powers = Attributes(c.Row, 1)
n = 0
Else
Powers = Powers + ", " & Attributes(c.Row, 1)
End If
End If
Next i
Next c
Magistry = Powers
Exit Function
Catcher:
Magistry = "You Lose"
End Function
使用 ALTF11 进入开发人员窗口,插入一个模块然后复制并粘贴此函数。返回 excel 并用作公式:
=magistry(ItemList, Inventory, Attributes)