VlookUP函數(shù)只能返回第一個值,無法返回多個值
下面這個自定義函數(shù)可以解決這個問題
可以這么理解,是Vlookup函數(shù)返回多個值,將其對應(yīng)的所有值都列出來
Function LookS(rng As Range, rg As Range, i As Byte, ii As Integer)
‘第1參數(shù)為查找的單元格,第2參數(shù)是查找范圍,第3參數(shù)為返回的列,第4參數(shù)為返回的第幾個值
‘第1參數(shù)和第2參數(shù)都要鎖定行
Dim arr, a%, x%
arr = rg
For a = 1 To UBound(arr, 1)
If arr(a, 1) = rng Then
x = x + 1
If x = ii Then LookS = arr(a, i): Exit For
End If
Next
If a > UBound(arr, 1) Then LookS = ""
End Function
excel vba中Vlookup返回多個值 自定義函數(shù)
excel vba中Vlookup返回多個值 自定義函數(shù)