Dim f, titre, col
Option Compare Text
Private Sub UserForm_Initialize()
Set f = Sheets("Liste")
Me.OptionButton1 = True
titre = "Acteur": AlimComboBox
End Sub
Private Sub OptionButton1_Click()
titre = "Acteur": AlimComboBox
End Sub
Private Sub OptionButton2_Click()
titre = "Titre de film": AlimComboBox
End Sub
Private Sub OptionButton3_Click()
titre = "Genre": AlimComboBox
End Sub
Private Sub OptionButton4_Click()
titre = "Nationalite": AlimComboBox
End Sub
Sub AlimComboBox()
col = Application.Match(titre, f.[B5:F5], 0) + 1
If IsError(col) Then Exit Sub
Set mondico = CreateObject("Scripting.Dictionary")
a = f.Cells(6, col).Resize(f.Cells(65000, col).End(xlUp).Row)
For i = LBound(a) To UBound(a)
If a(i, 1) <> "" Then mondico(a(i, 1)) = ""
Next i
temp = mondico.keys
Call Tri(temp, LBound(temp), UBound(temp))
Me.ComboBox1.ListIndex = -1
Me.ComboBox1.List = temp
End Sub
Private Sub ComboBox1_click()
bd = Range("b6:F" & [b65000].End(xlUp).Row)
c = Application.Match(titre, f.[B5:F5], 0)
Me.ListBox1.Clear
j = 0
For i = LBound(bd) To UBound(bd)
If Me.ComboBox1 = bd(i, c) Then
Me.ListBox1.AddItem bd(i, 1)
Me.ListBox1.List(j, 1) = bd(i, 2)
Me.ListBox1.List(j, 2) = bd(i, 3)
Me.ListBox1.List(j, 3) = bd(i, 4)
j = j + 1
End If
Next i
End Sub
Private Sub ListBox1_Click()
Me.TextBox1 = Me.ListBox1
Me.TextBox2 = Me.ListBox1.Column(1)
Me.TextBox3 = Me.ListBox1.Column(2)
Me.TextBox4 = Me.ListBox1.Column(3)
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