你可以通過VLOOKUP函數創建一個用戶函數循環值:
Function VLOOKUPARRAY(ByVal lookup_val As Range, ByVal table_array As Range, ByVal col_index_num As Integer, Optional ByVal range_lookup As Integer = 0) As String
Dim s As String
Dim a1() As String
Dim a2() As Variant
Dim i As Integer
'Recalculate whenever a calculation happens on the worksheet
Application.Volatile
'Get the lookup value from the cell
s = lookup_val.Value
'Split into array
a1 = Split(s, ",")
'Set output array to input array dimensions
ReDim a2(0 To UBound(a1))
'Loop through input array and set output array elements to lookup results using application lookup function.
For i = 0 To UBound(a1)
a2(i) = Application.WorksheetFunction.VLookup(Trim(a1(i)), table_array, col_index_num, range_lookup)
Next i
'Loop through output array and load values into a string
s = ""
For i = 0 To UBound(a2)
s = s & a2(i) & ", "
Next i
'Knock the final ", " off the end of the string
s = Left(s, Len(s) - Len(", "))
'Set function output to string value.
VLOOKUPARRAY = s
End Function
這是快速和骯髒的,但它給了我所需的輸出。根據需要調整。
從你的問題中不清楚你想達到什麼。試着提供一個例子和預期的結果,所以其他人會理解你。 – tarashypka
@tarashpka檢查是否有幫助 – rockedbyjava