Function intersection(ByVal x As Collection, ByVal Y As Collection) As Collection
Dim I As Long, J As Long, z As New Collection, repeat As Boolean
If x.Count * Y.Count = 0 Then Set intersection = Nothing
Set z = x
For I = z.Count To 1 Step -1
For J = 1 To Y.Count
repeat = False
If Y(J) = z(I) Then repeat = True: Exit For
Next
If repeat = False Then z.Remove I
Next
Set intersection = z
Set z = Nothing
End Function
Private Sub Command1_Click()
Dim A As New Collection
Dim B As New Collection
Dim C As New Collection
Debug.Print " COLLECTION A:"
For I = 1 To 26
A.Add Chr(I + 60)
Debug.Print A(I)
Next
Debug.Print " COLLECTION B:"
For I = 1 To 50
B.Add Chr(I + 64)
Debug.Print B(I)
Next
Set C = intersection(A, B)
Debug.Print " intersection(A AND B):"
For I = 1 To C.Count
Debug.Print C(I)
Next
End Sub