Sub Init1()
Dim NoDept As New Collection
Dim A()
Dim i%, J%, NoValeur%
Dim Swap1$, Swap2$
Dim Cp%, Nb%
Dim AL As Object
Cp = Int(Label4.Caption)
'CP = 13
Application.ScreenUpdating = False
Sheets("Feuil2").Activate
On Error Resume Next
Range(Cells(3, Cp), Cells(65536, Cp).End(xlUp)).Select
A = Selection.Value
For i = 1 To UBound(A, 1)
NoDept.Add A(i, 1), CStr(A(i, 1))
Next i
'----------- Tri Communes ------------
For i = 1 To NoDept.Count - 1
For J = i + 1 To NoDept.Count
If NoDept(i) > NoDept(J) Then
Swap1 = NoDept(i)
Swap2 = NoDept(J)
NoDept.Add Swap1, before:=J
NoDept.Add Swap2, before:=i
NoDept.Remove i + 1
NoDept.Remove J + 1
End If
Next J
Next i
' partie modifiée
'-------- Chargement Combo CP --------
Set AL = CreateObject("System.Collections.ArrayList")
'chargement des CP formatés dans l'objet ArrayList
For J = 1 To NoDept.Count
AL.Add Format(NoDept(J), "00000") 'format des CP
Next J
AL.Sort 'tri des CP
'on charge les CP triés dans le ComboBox des CP
For J = 0 To AL.Count
Me.cboCP.AddItem AL(J)
NoValeur = NoValeur + 1 'cette ligne existait donc je l'ai laissée mais est-elle vraiment utile ?
Next J
'fin de la partie modifiée
Nb = Sheets("Feuil2").Cells(65536, Cp).End(xlUp).Row
Label10.Caption = "Nombre de communes Q = " & Nb - 2
[A1].Select
End Sub