Re : Activer des filtres via userform comme sur une feuille excel
Bonjour à toute la communauté
J'ai essayé de comprendre le code de formcascadeorde si dessous que je trouve excellente.
Cependant j'arrive à ajouter 10 combobox donc jusqu'a la colonne "J" , pour le K cela ne fonctionne pas
Si quelqu'un pouvait m'expliquer , je rame depuis des jours dessus.
je vous mes mon code qui marche jusqu'à J
Si quelqu'un peux m'éclairer car j'ai plus de cheveux
.
Dim f, bd
Private Sub ListBox1_Click()
End Sub
Private Sub UserForm_Initialize()
Set f = Sheets("bd")
Set bd = f.Range("a2:J" & f.[A65000].End(xlUp).Row)
For c = 1 To 6
ListeCol c
Next c
filtre
For i = 1 To 6: Me("label" & i) = f.Cells(1, i): Next i
End Sub
Private Sub ComboBox1_DropButtonClick()
ListeCol 1
End Sub
Private Sub ComboBox2_DropButtonClick()
ListeCol 2
End Sub
Private Sub ComboBox3_DropButtonClick()
ListeCol 3
End Sub
Private Sub ComboBox4_DropButtonClick()
ListeCol 4
End Sub
Private Sub ComboBox5_DropButtonClick()
ListeCol 5
End Sub
Private Sub ComboBox6_DropButtonClick()
ListeCol 6
End Sub
Private Sub ComboBox7_DropButtonClick()
ListeCol 7
End Sub
Private Sub ComboBox8_DropButtonClick()
ListeCol 8
End Sub
Private Sub ComboBox9_DropButtonClick()
ListeCol 9
End Sub
Private Sub ComboBox10_DropButtonClick()
ListeCol 10
End Sub
Private Sub ComboBox11_DropButtonClick()
ListeCol 11
End Sub
Sub ListeCol(noCol)
Set MonDico = CreateObject("Scripting.Dictionary")
For i = 1 To bd.Rows.Count
ok = True
For n = 1 To bd.Columns.Count
If n <> noCol Then
If Not bd.Cells(i, n) Like Me("comboBox" & n) Then ok = False
End If
Next n
If ok Then
tmp = bd.Cells(i, noCol)
MonDico(tmp) = tmp
End If
Next i
MonDico.Add "*", "*"
temp = MonDico.items
Call Tri(temp, LBound(temp), UBound(temp))
Me("ComboBox" & noCol).List = temp
End Sub
Sub Tri(a, gauc, droi) ' Quick sort
ref = CStr(a((gauc + droi) \ 2))
g = gauc: d = droi
Do
Do While CStr(a(g)) < ref: g = g + 1: Loop
Do While ref < CStr(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_Change()
filtre
End Sub
Private Sub ComboBox2_Change()
filtre
End Sub
Private Sub ComboBox3_Change()
filtre
End Sub
Private Sub ComboBox4_Change()
filtre
End Sub
Private Sub ComboBox5_Change()
filtre
End Sub
Private Sub ComboBox6_Change()
filtre
End Sub
Private Sub ComboBox7_Change()
filtre
End Sub
Private Sub ComboBox8_Change()
filtre
End Sub
Private Sub ComboBox9_Change()
filtre
End Sub
Private Sub ComboBox10_Change()
filtre
End Sub
Private Sub ComboBox11_Change()
filtre
End Sub
Sub filtre()
ligne = 0
Me.ListBox1.Clear
For i = 1 To bd.Rows.Count
ok = True
For n = 1 To bd.Columns.Count
If Not bd.Cells(i, n) Like Me("comboBox" & n) Then ok = False
Next n
If ok Then
Me.ListBox1.AddItem
For k = 1 To bd.Columns.Count
Me.ListBox1.List(ligne, k - 1) = bd.Cells(i, k)
Next k
Me.ListBox1.List(ligne, 6) = bd.Cells(i, k)
ligne = ligne + 1
End If
Next i
End Sub
Private Sub CommandButton1_Click()
Sheets("result").[A2:F1000].Clear
Sheets("result").[A2].Resize(Me.ListBox1.ListCount, 6) = Me.ListBox1.List
End Sub