可乐人
幼苗
共回答了17个问题采纳率:88.2% 举报
不固定参数,使用方法:
=f(a1,a2,a3)
-----------------
Function f(ParamArray x() As Variant)
'求多个单元格数据的交集
'单元格内容格式:1,23,5,26,14
Application.Volatile
Dim d1,d2,iKeys,i,j,k,a()
Set d1 = CreateObject("Scripting.Dictionary")
Set d2 = CreateObject("Scripting.Dictionary")
ReDim a(LBound(x) To UBound(x))
For i = LBound(x) To UBound(x)
x(i) = Trim(Replace(x(i),","," "))
a(i) = Split(x(i)," ")
Next
i = LBound(a)
For j = LBound(a(i)) To UBound(a(i))
d1(a(i)(j)) = a(i)(j)
Next j
For i = LBound(a) + 1 To UBound(a)
If d1.Count < 1 Then
f = ""
GoTo 100
Else
iKeys = d1.keys
End If
For j = LBound(a(i)) To UBound(a(i))
d2(a(i)(j)) = a(i)(j)
Next j
For j = LBound(iKeys) To UBound(iKeys)
If Not d2.Exists(iKeys(j)) Then d1.Remove (iKeys(j))
Next j
d2.RemoveAll
Next i
If d1.Count < 1 Then
f = ""
GoTo 100
Else
iKeys = d1.keys
f = Join(iKeys,",")
End If
Exit Function
100:
Set d1 = Nothing
Set d2 = Nothing
End Function
1年前
1