1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| 'Cocher la référence: Microsoft Scripting Runtime
Private Sub UserForm_Initialize()
Dim Lastlig As Long, i As Long
Dim MonDico As New Scripting.Dictionary
Dim Tb
With Worksheets("Feuil1")
Lastlig = .Cells(.Rows.Count, "G").End(xlUp).Row
Tb = .Range("G11:G" & Lastlig).Value
End With
For i = 1 To UBound(Tb, 1)
If Not MonDico.Exists(Tb(i, 1)) Then MonDico.Add Tb(i, 1), Tb(i, 1)
Next i
If MonDico.Count > 0 Then
For i = 0 To MonDico.Count - 1
Me.ComboBox1.AddItem MonDico.Items(i)
Next i
End If
Set MonDico = Nothing
End Sub
Private Sub ComboBox1_Change()
Dim Nom As String, Sans As String, Avec As String
Dim Lastlig As Long, i As Long
Dim MonDico As New Scripting.Dictionary
Dim Tb
Me.ComboBox2.Clear
If Me.ComboBox1.ListIndex > -1 Then
Nom = Me.ComboBox1.Value
With Worksheets("Feuil1")
Lastlig = .Cells(.Rows.Count, "G").End(xlUp).Row
Tb = .Range("G11:I" & Lastlig).Value
End With
For i = 1 To UBound(Tb, 1)
If Tb(i, 1) <> Nom Then
Sans = Sans & "|" & Tb(i, 3)
Else
Avec = Avec & "|" & Tb(i, 3)
End If
Next i
Tb = Split(Sans, "|")
For i = LBound(Tb) To UBound(Tb)
If InStr(Avec, Tb(i)) = 0 Then
If Not MonDico.Exists(Tb(i)) Then MonDico.Add Tb(i), Tb(i)
End If
Next i
If MonDico.Count > 0 Then
For i = 0 To MonDico.Count - 1
Me.ComboBox2.AddItem MonDico.Items(i)
Next i
End If
Set MonDico = Nothing
End If
End Sub |
Partager