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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| '== On déclare la variable public pour la feuille de travail ==
Dim f
'== CommandButton1 : Reset filter ==
Private Sub CommandButton1_Click()
'==== On efface toutes les données
Me.ComboBox1.Clear
Me.ComboBox2.Clear
Me.ComboBox3.Clear
Me.ListBox1.Clear
Me.ListBox2.Clear
'==== On réinitialise l'UserForm
UserForm_Initialize
End Sub
'== CommandButton2 : Close UserForm ==
Private Sub CommandButton2_Click()
'==== On ferme l'UserForm
Unload MyUserForm
End Sub
'== On initialise l'UserFrom ==
Private Sub UserForm_Initialize()
'==== On déclare la feuille sur laquelle on travail
Set f = Sheets("BD")
'==== On vient sur le ComboxBox1 lors du démarrage
Me.ComboBox1.SetFocus
'==== On créé le dictionnaire
Set mondico = CreateObject("Scripting.Dictionary")
'==== On déclare la plage pour la ComboBox1
For Each c In Range("H2:H" & [H65000].End(xlUp).Row)
mondico(c.Value) = ""
Next c
'==== On vient remplir une variable, ici temp, qui vient lister toutes les données
temp = mondico.keys
'==== On appelle la fonction Tri pour trier la ComboBox1
Call Tri(temp, LBound(temp), UBound(temp))
'==== Une fois trié on remplit la ComboBox1
Me.ComboBox1.List = temp
End Sub
'== Lorsque l'on clique sur le ComboBox1, cela rempli la ComboBox2 ==
Private Sub ComboBox1_click()
Me.ComboBox2.Clear
Me.ComboBox3.Clear
Me.ListBox1.Clear
Me.ListBox2.Clear
Set mondico = CreateObject("Scripting.Dictionary")
For Each c In Range("H2:H" & [H65000].End(xlUp).Row)
If c = Me.ComboBox1 Then mondico(c.Offset(0, 3).Value) = ""
Next c
temp = mondico.keys
Call Tri(temp, LBound(temp), UBound(temp))
Me.ComboBox2.List = temp
End Sub
'== Lorsque l'on clique sur le ComboBox2, cela rempli la ComboBox3 ==
Private Sub ComboBox2_click()
Me.ComboBox3.Clear
Me.ListBox1.Clear
Me.ListBox2.Clear
Set mondico = CreateObject("Scripting.Dictionary")
For Each c In Range("D2:D" & [D65000].End(xlUp).Row)
If c.Offset(, 4) = Me.ComboBox1 And c.Offset(, 7) = Me.ComboBox2 Then mondico(c.Value) = ""
Next c
temp = mondico.keys
'Call Tri(temp, LBound(temp), UBound(temp))
Me.ComboBox3.List = temp
End Sub
'== Lorsque l'on clique sur le ComboBox3, cela rempli la ListBox1 ==
Private Sub ComboBox3_click()
Me.ListBox1.Clear
Me.ListBox2.Clear
Set mondico = CreateObject("Scripting.Dictionary")
i = 0
For Each c In Range("I2:I" & [I65000].End(xlUp).Row)
If c.Offset(, -1) = Me.ComboBox1 And c.Offset(, 2) = Me.ComboBox2 And c.Offset(, -5).Value = Me.ComboBox3 Then
mondico(c.Value) = ""
Me.ListBox1.AddItem c
i = i + 1
End If
Next c
temp = mondico.keys
Call Tri(temp, LBound(temp), UBound(temp))
Me.ListBox1.List = temp
Me.ListBox1.MultiSelect = fmMultiSelectMulti
End Sub
'== Lorsque l'on change une donnée dans la ListBox1, cela rempli la ListBox2 ==
Private Sub ListBox1_Change()
Me.ListBox2.Clear
Set mondico = CreateObject("Scripting.Dictionary")
For Each c In Range(f.[I2], f.[I65000].End(xlUp))
For k = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(k) = True Then
If c = Me.ListBox1.List(k, 0) Then
temp = c.Offset(, 1)
mondico(temp) = temp
End If
End If
Next k
Next c
temp = mondico.keys
Call Tri(temp, LBound(temp), UBound(temp))
Me.ListBox2.List = temp
End Sub
'== Fonction Tri
Sub Tri(a, gauc, droi)
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While a(g) < ref: g = g + 1: Loop
Do While ref < a(d): d = d - 1: Loop
If g <= d Then
temp = a(g): a(g) = a(d): a(d) = temp
g = g + 1: d = d - 1
End If
Loop While g <= d
If g < droi Then Call Tri(a, g, droi)
If gauc < d Then Call Tri(a, gauc, d)
End Sub |
Partager