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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
Option Explicit
Public Formations() As Variant
Sub TestChargerLaListeDesFormations()
Erase Formations
ChargerLaListeDesFormations ActiveSheet.Range("B1:K1")
With UserForm1
.ListBox1.Column = Formations
.Show
End With
End Sub
Sub ChargerLaListeDesFormations(ByVal AireFormations As Range)
Dim ListeFormations As Object
Dim CelluleFormation As Range
Dim ListeCles As Variant, ListeElements As Variant
Dim I As Integer, J As Integer
Dim Temp1 As Variant, Temp2 As Variant
Set ListeFormations = CreateObject("Scripting.Dictionary")
For Each CelluleFormation In AireFormations
If Not ListeFormations.Exists(CStr(CelluleFormation)) Then
ListeFormations.Add CStr(CelluleFormation), CelluleFormation.Offset(1, 0)
End If
Next CelluleFormation
ListeCles = ListeFormations.keys
' Tri des formations par ordre alphabétique
'------------------------------------------
For I = LBound(ListeCles) To UBound(ListeCles) - 1
For J = I + 1 To UBound(ListeCles)
If ListeCles(I) > ListeCles(J) Then
Temp1 = ListeCles(I)
ListeCles(I) = ListeCles(J)
ListeCles(J) = Temp1
End If
Next J
Next I
For I = LBound(ListeCles) To UBound(ListeCles)
ReDim Preserve Formations(1, I)
Formations(0, I) = ListeCles(I)
Formations(1, I) = 0
Next I
' Chargement de la matrice fes formations
'----------------------------------------
For I = LBound(Formations, 2) To UBound(Formations, 2)
For Each CelluleFormation In AireFormations
If CStr(CelluleFormation.Value) = CStr(Formations(0, I)) Then
If CDate(CelluleFormation.Offset(1, 0)) > CDate(Formations(1, I)) Then
Formations(1, I) = CelluleFormation.Offset(1, 0)
End If
End If
Next CelluleFormation
Next I
' For I = LBound(Formations, 2) To UBound(Formations, 2)
' Debug.Print Formations(0, I) & " : " & CDate(Formations(1, I))
' Next I
Set ListeFormations = Nothing
End Sub |
Partager