Utilisation d'un dictionary
Bonjour,
j'ai une chtite question sur les dictionary
Je ne comprends pas pourquoi un de mes codes ne marche pas
voici la partie commune
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| Public Dico As Scripting.Dictionary
Sub Main()
Call Calcul
Call Affiche
End Sub
Sub Calcul()
i = 2
If Not Dico Is Nothing Then
Set Dico = Nothing
End If
Set Dico = CreateObject("Scripting.Dictionary")
While ThisWorkbook.Sheets("Champs").Cells(i, 1) <> ""
Dico.Add ThisWorkbook.Sheets("Champs").Cells(i, 1), Int(14 * Rnd())
i = i + 1
Wend
End Sub |
Voici la macro Affiche qui marche
Code:
1 2 3 4 5 6 7 8 9 10 11 12
| Sub Affiche()
i = 2
Do While ThisWorkbook.Sheets("Champs").Cells(i, 1) <> ""
For Each Element In Dico
If Element = ThisWorkbook.Sheets("Champs").Cells(i, 1) Then
MsgBox Dico.Item(Element)
Exit For
End If
Next
i = i + 1
Loop
End Sub |
Et voila la macro Affiche qui ne marche pas
Code:
1 2 3 4 5 6 7
| Sub Affiche()
i = 2
Do While ThisWorkbook.Sheets("Champs").Cells(i, 1) <> ""
MsgBox Dico.Item(ThisWorkbook.Sheets("Champs").Cells(i, 1))
i = i + 1
Loop
End Sub |
Quelqu'un sait pourquoi? Ca vient d'un format?
Si ca ne marche vraiment pas, quelq'un connait un objet autre que Dictionnary qui permet de faire cela?
Merci d'avance