Private Sub IniCbo1()
Dim Ws As Worksheet, MonDico As Object, Temp(), Cel As Range
ComboBox1.Clear
' Définir un nouveau dictionnaire
Set MonDico = CreateObject("Scripting.Dictionary")
' Pour chaque feuille du classeur
For Each Ws In Worksheets
' Si le début du nom de la feuille commence par "IO"
If Left(Ws.Name, 2) = "IO" Then
' Si la fin du nom de la feuille se termine par "PROVOX"
If Right(Ws.Name, 6) = "PROVOX" Then
With Ws
' On trie la colonne D
.Range("A1").Sort Key1:=.Columns("D"), Header:=xlGuess
' Pour chaque cellule de cette colonne
For Each Cel In .Range("D2:D" & .Range("D65536").End(xlUp).Row)
' Si la valeur de la cellule n'est pas vide
If Cel <> "" Then
' On ajoute la valeur au DICO = valeur unique
If Not MonDico.Exists(Cel.Value) Then MonDico.Add Cel.Value, Cel.Value
End If
Next Cel
End With
Else
' Sinon si la feuille ne se termine pas par "PROVOX"
With Ws
' On trie la colonne B
.Range("A1").Sort Key1:=.Columns("B"), Header:=xlGuess
' Pour chaque cellule de cette colonne
For Each Cel In .Range("B2:B" & .Range("B65536").End(xlUp).Row)
' Si la valeur de la cellule n'est pas vide
If Cel <> "" Then
' On ajoute la valeur au DICO = valeur unique
If Not MonDico.Exists(Cel.Value) Then MonDico.Add Cel.Value, Cel.Value
End If
Next Cel
End With
End If
End If
Next Ws
ReDim Temp(MonDico.Count)
Temp = MonDico.items
Call Tri(Temp, LBound(Temp), UBound(Temp))
ComboBox1.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