1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
Private Sub UserForm_Initialize()
Dim BDF As Worksheet
Dim l As Range
Dim t_prem As Range, t_dern As Range
Set BDF = Worksheets("Feuil2")
Set t_prem = BDF.Range("A1")
Set t_dern = BDF.Range("A65536").End(xlUp)
Dim tablo()
ReDim tablo(2, 0)
ListBox1.ColumnCount = 2 '2 colonnes dans la listBox
ListBox1.ColumnWidths = "0"
'rend invisible la première colonne
ListBox1.Clear
'Mise en tableau des infos
For Each l In BDF.Range(t_prem, t_dern)
If l.Value <> "" Then
tablo(1, UBound(tablo, 2)) = l.Column
tablo(2, UBound(tablo, 2)) = l.Value
ReDim Preserve tablo(2, UBound(tablo, 2) + 1)
End If
Next
'Tri du tableau
For n = LBound(tablo, 2) To UBound(tablo, 2) - 1
For M = LBound(tablo, 2) To UBound(tablo, 2) - 1
If tablo(2, M) > tablo(2, n) Then
temp1 = tablo(1, n)
temp2 = tablo(2, n)
tablo(1, n) = tablo(1, M)
tablo(2, n) = tablo(2, M)
tablo(1, M) = temp1
tablo(2, M) = temp2
End If
Next M
Next n
'Transfert du tableau vers la listbox
For n = LBound(tablo, 2) To UBound(tablo, 2) - 1
ListBox1.AddItem tablo(1, n)
ListBox1.List(ListBox1.ListCount - 1, 1) = tablo(2, n)
Next n
End Sub |
Partager