Gibt es eine Find-Methode bei VBA Dictionarys?

  • Excel

Es gibt 4 Antworten in diesem Thema. Der letzte Beitrag () ist von Mono.

    Gibt es eine Find-Methode bei VBA Dictionarys?

    Hi Leute,

    ich benutze ein VBA-Dictionary. Ich muss nun in diesem Dictionary nach bestimmten Key-Value-Pairs suchen. Da ich keine Methode gefunden habe, die einem "Find" gleichkommt und ich zwei verschachtelte for-Schleifen als sehr träge finde, hoffe ich, dass mir jemand weiter helfen kann.

    Mein Problem gestaltet sich dermaßen:

    Pseudocode:

    Visual Basic-Quellcode

    1. Dim myDict1 as dict
    2. Dim myDict2 as dict
    3. for i to end myDict1
    4. for j to end myDict2
    5. Set myDict1 = myDict1.Items(i)
    6. Set myDict2 = myDict2.Items(j)
    7. If myDict1.Keys(i) = myDict2.Keys(j
    8. 'blabla
    9. End If


    Das ist quasi das was ich eigentlich vorhabe. Nun weiß ich aber, dass verschachtelte Schleife langsam sind. Gibt es eine schnellere Find-Methode?

    Visual Basic-Quellcode

    1. Option Explicit
    2. Sub comp()
    3. Dim myDict1 As New Dictionary
    4. Dim a As Long
    5. Dim myDict2 As New Dictionary
    6. Dim itm As Variant
    7. For a = 0 To 2000
    8. myDict1.Add a, CStr(a)
    9. myDict2.Add a + 1990, CStr(a + 1990)
    10. Next
    11. For Each itm In myDict1.keys
    12. If myDict2.Exists(itm) Then
    13. Debug.Print ("Existiert in beiden Dictionarys: " & itm)
    14. End If
    15. Next
    16. End Sub
    Das ist meine Signatur und sie wird wunderbar sein!