Option Compare Text
Dim MaListe As ListObject
Dim mondico
Private Sub UserForm_Initialize()
Dim temp
Dim c As Range
Set MaListe = Sheets("Liste de prix").ListObjects("Tableau1")
Set mondico = CreateObject("Scripting.Dictionary")
'For Each c In Range("Tableau1[Colonne1]")
For Each c In MaListe.DataBodyRange.Columns(2).Cells
If c.Value <> "" Then mondico.Item(c.Value) = c.Value
Next c
temp = mondico.items
Call tri(temp, LBound(temp), UBound(temp))
Me.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
Private Sub ComboBox1_Click()
Me.ComboBox2.Clear
Set mondico = CreateObject("Scripting.Dictionary")
For Each c In MaListe.DataBodyRange.Columns(2).Cells
If c = Me.ComboBox1 Then mondico(c.Offset(, 1).Value) = "" ' si famille alors on ajoute l'élément de la sous-famille au dictionnaire
Next c
Me.ComboBox2.List = mondico.keys
End Sub
Private Sub ComboBox2_Click()
For Each c In MaListe.DataBodyRange.Columns(2).Cells
If c = Me.ComboBox1 And c.Offset(, 1) = Me.ComboBox2 Then
Me.TextBox1 = c.Offset(, 2)
Me.TextBox2 = c.Offset(, 3)
End If
Next c
End Sub
Private Sub CommandButton1_Click()
ActiveCell = Me.ComboBox2
ActiveCell.Offset(, 2) = CDbl(Me.TextBox1)
ActiveCell.Offset(, 3) = CDbl(Me.TextBox2)
Unload Me
End Sub