Vergleich Werte Dictionary/Zelle
12.06.2016 18:37:51
Sofie
Hallo Leute ich habe mal wieder ein Problem und zwar möchte ich Werte aus meinem Dictionary mit Werten aus Zellen vergleichen und anschließend geordnet ausgeben. Wenn ich über meine MsgBox abfragen zum Typ mache sind sowohl die Werte im Dictionary als auch die Werte in den Zellen com Typ "String". Beim Vergleich der Werte werden identische Werte dennoch nicht als identisch erkannt. Ich hoffe das war einigermaßen verständlich erklärt. Anbei mein code.Habt ihr ne idee woran das liegen könnte?
Private Sub test()
Dim myDic As Object
Dim z As Variant
Dim ar As Variant
lr = Cells(Rows.Count, "A").End(xlUp).Row
Set myDic = CreateObject("Scripting.Dictionary")
With myDic
For i = 2 To lr
.Item(Cells(i, "H").Value) = 1
If Not .exists(Cells(i, "H").Value) Then
.Add (Cells(i, "H").Value), Cells(i, "B")
End If
Next i
ar = myDic.Keys
AnzahlWerte = myDic.Count
End With
MsgBox TypeName(ar(1)) 'Ausgabe: String
MsgBox TypeName(Cells(2, "H").Value) 'Ausgabe: Strint
For i = 0 To AnzahlWerte - 1 'Werte in Dictionary
For z = 2 To lr 'Spalten
If (ar(i)) = (Cells(z, "H").Value) Then
Cells(z, "M").Value = ar(i)
Cells(z, "N").Value = Cells(z, "A").Value
' Else: MsgBox ar(i) & " ist nicht gleich" & " " & Cells(2, "H").Value
End If
Next z
Next i
End Sub