电脑教程
位置:首页>> 电脑教程>> office教程>> excel vba中Vlookup返回多个值 自定义函数

excel vba中Vlookup返回多个值 自定义函数

  发布时间:2023-12-09 14:45:52 

标签:函数,多个,自定义,返回,Excel函数

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

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

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

Function LookS(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

excel vba中Vlookup返回多个值 自定义函数

excel vba中Vlookup返回多个值 自定义函数

0
投稿

猜你喜欢

手机版 电脑教程 asp之家 www.aspxhome.com