Type : Microsoft office Excel 2003
Bonjour,
Je suis certain qu'il y a moyen de simplifier cette macro. Etant novice, je fais appel à vos connaissances.
J'ai testé avec des variables... mais je ne suis pas un expert.
En vous remerciant,
Private Sub ComboBox4_Change()
ListBox1.Clear
If ComboBox4.Text = "" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
End If
If ComboBox4.Text = "7" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=7"
End If
If ComboBox4.Text = "8" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=8"
End If
If ComboBox4.Text = "9" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=9"
End If
If ComboBox4.Text = "10" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=10"
End If
If ComboBox4.Text = "11" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=11"
End If
If ComboBox4.Text = "12" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=12"
End If
If ComboBox4.Text = "13" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=13"
End If
If ComboBox4.Text = "14" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=14"
End If
If ComboBox4.Text = "15" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=15"
End If
If ComboBox4.Text = "16" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=16"
End If
If ComboBox4.Text = "17" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=17"
End If
If ComboBox4.Text = "18" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=18"
End If
If ComboBox4.Text = "19" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=19"
End If
If ComboBox4.Text = "20" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=20"
End If
If ComboBox4.Text = "21" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=21"
End If
If ComboBox4.Text = "22" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=22"
End If
If ComboBox4.Text = "23" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=23"
End If
If ComboBox4.Text = "24" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=24"
End If
If ComboBox4.Text = "25" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=25"
End If
If ComboBox4.Text = "26" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=26"
End If
If ComboBox4.Text = "27" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=27"
End If
If ComboBox4.Text = "28" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=28"
End If
If ComboBox4.Text = "29" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=29"
End If
If ComboBox4.Text = "30" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=30"
End If
If ComboBox4.Text = "31" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=31"
End If
If ComboBox4.Text = "32" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=32"
End If
If ComboBox4.Text = "33" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=33"
End If
If ComboBox4.Text = "34" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=34"
End If
If ComboBox4.Text = "35" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=35"
End If
If ComboBox4.Text = "36" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=36"
End If
If ComboBox4.Text = "37" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=37"
End If
If ComboBox4.Text = "38" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=38"
End If
If ComboBox4.Text = "39" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=39"
End If
If ComboBox4.Text = "40" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=40"
End If
If ComboBox4.Text = "41" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=41"
End If
If ComboBox4.Text = "42" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=42"
End If
If ComboBox4.Text = "43" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=43"
End If
If ComboBox4.Text = "44" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=44"
End If
If ComboBox4.Text = "45" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=45"
End If
If ComboBox4.Text = "46" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=46"
End If
If ComboBox4.Text = "47" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=47"
End If
If ComboBox4.Text = "48" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=48"
End If
If ComboBox4.Text = "49" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=49"
End If
If ComboBox4.Text = "50" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=50"
End If
Dim Cell As Range
Dim Unique As New Collection
Dim Valeur As Range
Dim i As Integer
i = Range("B65536").End(xlUp).Row
On Error Resume Next
For Each Cell In Range("B2:B" & i)
If Not Cell.EntireRow.Hidden Then Unique.Add Cell, CStr(Cell)
Next Cell
On Error GoTo 0
For Each Valeur In Unique
Me.ListBox1.AddItem Valeur
Next Valeur
End Sub
Bonjour,
Je suis certain qu'il y a moyen de simplifier cette macro. Etant novice, je fais appel à vos connaissances.
J'ai testé avec des variables... mais je ne suis pas un expert.
En vous remerciant,
Private Sub ComboBox4_Change()
ListBox1.Clear
If ComboBox4.Text = "" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
End If
If ComboBox4.Text = "7" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=7"
End If
If ComboBox4.Text = "8" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=8"
End If
If ComboBox4.Text = "9" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=9"
End If
If ComboBox4.Text = "10" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=10"
End If
If ComboBox4.Text = "11" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=11"
End If
If ComboBox4.Text = "12" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=12"
End If
If ComboBox4.Text = "13" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=13"
End If
If ComboBox4.Text = "14" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=14"
End If
If ComboBox4.Text = "15" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=15"
End If
If ComboBox4.Text = "16" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=16"
End If
If ComboBox4.Text = "17" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=17"
End If
If ComboBox4.Text = "18" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=18"
End If
If ComboBox4.Text = "19" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=19"
End If
If ComboBox4.Text = "20" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=20"
End If
If ComboBox4.Text = "21" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=21"
End If
If ComboBox4.Text = "22" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=22"
End If
If ComboBox4.Text = "23" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=23"
End If
If ComboBox4.Text = "24" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=24"
End If
If ComboBox4.Text = "25" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=25"
End If
If ComboBox4.Text = "26" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=26"
End If
If ComboBox4.Text = "27" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=27"
End If
If ComboBox4.Text = "28" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=28"
End If
If ComboBox4.Text = "29" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=29"
End If
If ComboBox4.Text = "30" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=30"
End If
If ComboBox4.Text = "31" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=31"
End If
If ComboBox4.Text = "32" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=32"
End If
If ComboBox4.Text = "33" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=33"
End If
If ComboBox4.Text = "34" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=34"
End If
If ComboBox4.Text = "35" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=35"
End If
If ComboBox4.Text = "36" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=36"
End If
If ComboBox4.Text = "37" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=37"
End If
If ComboBox4.Text = "38" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=38"
End If
If ComboBox4.Text = "39" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=39"
End If
If ComboBox4.Text = "40" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=40"
End If
If ComboBox4.Text = "41" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=41"
End If
If ComboBox4.Text = "42" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=42"
End If
If ComboBox4.Text = "43" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=43"
End If
If ComboBox4.Text = "44" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=44"
End If
If ComboBox4.Text = "45" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=45"
End If
If ComboBox4.Text = "46" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=46"
End If
If ComboBox4.Text = "47" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=47"
End If
If ComboBox4.Text = "48" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=48"
End If
If ComboBox4.Text = "49" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=49"
End If
If ComboBox4.Text = "50" Then
ListBox1.Clear
Selection.AutoFilter Field:=5
Selection.AutoFilter Field:=5, Criteria1:="<=50"
End If
Dim Cell As Range
Dim Unique As New Collection
Dim Valeur As Range
Dim i As Integer
i = Range("B65536").End(xlUp).Row
On Error Resume Next
For Each Cell In Range("B2:B" & i)
If Not Cell.EntireRow.Hidden Then Unique.Add Cell, CStr(Cell)
Next Cell
On Error GoTo 0
For Each Valeur In Unique
Me.ListBox1.AddItem Valeur
Next Valeur
End Sub