在EXCEL的A1:A5中分别有数据:1、1、2、3、1.在B1:B5中分别有数据:3、4、5、2、3.

2023-12-18 09:40:40
有4个网友回答
网友(1):

Public Function iLookUps(iVal As String, rng1 As Range, rng2 As Range)
Application.Volatile
Dim arr1, arr2, i, tmp
If rng1.Rows.Count <> rng2.Rows.Count Then
tmp = "#rng1.Rows <> rng2.Rows"
GoTo 1000
End If
arr1 = rng1.Columns(1)
arr2 = rng2.Columns(1)
tmp = ""
For i = 1 To UBound(arr1)
If CStr(iVal) = CStr(arr1(i, 1)) Then tmp = tmp & CStr(arr2(i, 1)) & ","
Next
If tmp <> "" Then tmp = Left(tmp, Len(tmp) - 1)
1000:
iLookUps = tmp
End Function
-----------
使用公式:
=iLookUps(1,A1:A5,B1:B5)
结果:
3,4,3

网友(2):

=VLOOKUP(数据X的单元格,$A$1:$B$5,2)

网友(3):

哇,有点难,先想想

网友(4):

比较高难度....