|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Function 交集(ParamArray Args())
Dim dic1, dic2, arr
Set dic1 = CreateObject("scripting.dictionary")
Set dic2 = CreateObject("scripting.dictionary")
For Each Rng In Args
k = k + 1
If k = 1 Then
arr = Rng
If Not IsArray(arr) Then
ReDim arr(1 To 1, 1 To 1)
arr(1, 1) = Rng
End If
For Each v In arr
dic1(v & "") = ""
Next
Else
arr = Rng
If Not IsArray(arr) Then
ReDim arr(1 To 1, 1 To 1)
arr(1, 1) = Rng
End If
dic2.RemoveAll
For Each v In arr
dic2(v & "") = ""
Next
For Each v In dic1.keys()
If Not dic2.exists(v) Then
dic1.Remove (v)
End If
Next
End If
Next
If dic1.Count > 0 Then
交集 = Application.Transpose(dic1.keys)
Else
交集 = ""
End If
Set dic1 = Nothing
Set dic2 = Nothing
End Function |
|