Skip to content

Instantly share code, notes, and snippets.

@syxolk
Created November 7, 2019 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save syxolk/fa6504e706dac054cdbad88a9ebbce10 to your computer and use it in GitHub Desktop.
Save syxolk/fa6504e706dac054cdbad88a9ebbce10 to your computer and use it in GitHub Desktop.
VBA Set Intersections
Option Explicit
Sub IntersectionMacro()
Dim set1 As New Scripting.Dictionary
Dim set2 As New Scripting.Dictionary
Dim result As New Scripting.Dictionary
set1.Add "M AB 123", ""
set1.Add "M CD 456", ""
set1.Add "M EF 789", ""
set1.Add "B AA 22", ""
set2.Add "M CD 456", ""
set2.Add "J GH 000", ""
set2.Add "M EF 789", ""
set2.Add "B AA 22", ""
set2.Add "EF ZZ 111", ""
Intersect set1, set2, result
Dim Key As Variant
Dim i As Integer
i = 1
For Each Key In result.Keys
Cells(i, 1) = Key
i = i + 1
Next Key
End Sub
Sub Intersect(set1 As Scripting.Dictionary, set2 As Scripting.Dictionary, ByRef result As Scripting.Dictionary)
Dim Key As Variant
For Each Key In set1.Keys
If set2.Exists(Key) Then
result.Add Key, ""
End If
Next Key
End Sub
@syxolk
Copy link
Author

syxolk commented Nov 7, 2019

Unter Extras -> Verweise ...

image

... muss die "Microsoft Scripting Runtime" aktiviert werden

image

@syxolk
Copy link
Author

syxolk commented Nov 7, 2019

Ergebnis: Schnittmenge aus den beiden Mengen von Kennzeichen

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment