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

2024-12-05 06:22:20
推荐回答(1个)
回答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