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
| Dim f
Private Sub UserForm_Initialize()
Set f = Sheets("base")
Set MonDico = CreateObject("Scripting.Dictionary")
For Each c In f.Range("B2:B" & f.[B65000].End(xlUp).Row) ' on explore la colonne de niveau 1
MonDico(c.Value) = "" ' on ajoute l'élément de la famille au dictionnaire
Next c
temp = MonDico.keys 'les clés du dico dans la table temp()
Call Tri(temp, LBound(temp), UBound(temp))
Me.Famille.List = temp
End Sub
Private Sub famille_click()
Me.SousFamille.Clear
Set MonDico = CreateObject("Scripting.Dictionary")
For Each c In f.Range("B2:B" & f.[B65000].End(xlUp).Row) ' on explore la colonne de niveau 1
If c = Me.Famille Then MonDico(c.Offset(, 1).Value) = "" ' si famille alors on ajoute l'élément de la sous-famille au dictionnaire
Next c
temp = MonDico.keys 'les clés du dico dans la table temp()
Call Tri(temp, LBound(temp), UBound(temp))
Me.SousFamille.List = temp
End Sub
Sub Tri(a, gauc, droi) ' Quick sort
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