Vlookup返回多个值 自定义函数

来源:互联网 发布:httpclient获取json 编辑:程序博客网 时间:2024/06/06 06:53

VlookUP函数只能返回第一个值,无法返回多个值

下面这个自定义函数可以解决这个问题

可以这么理解,是Vlookup函数返回多个值,将其对应的所有值都列出来

 

FunctionLookS(rng As Range, rg As Range, i As Byte, ii As Integer)
'第1参数为查找的单元格,第2参数是查找范围,第3参数为返回的列,第4参数为返回的第几个值

'第1参数和第2参数都要锁定行
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

Vlookup返回多个值 <wbr>自定义函数

Vlookup返回多个值 <wbr>自定义函数

原创粉丝点击