Sub ImportFichierCSV()
Dim fichier As Variant, t, x%, texte$, a(), i&, ub, b(), s, j%
fichier = Application.GetOpenFilename("Fichiers CSV (*.csv),*.csv")
If fichier = False Then Exit Sub
t = Timer
x = FreeFile
Open fichier For Input As #x 'ouverture en lecture séquentielle
Line Input #x, texte 'on saute 1 ligne
While Not EOF(x)
ReDim Preserve a(i)
Line Input #x, a(i)
i = i + 1
Wend
Close #x 'fermeture du fichier CSV
ub = UBound(a)
ReDim b(ub, 0) 'base 0
For i = 0 To ub
b(i, 0) = a(ub - i) 'inverse les lignes
s = Split(b(i, 0), ";") 'éclate le texte
For j = 1 To UBound(s): s(j) = Format(s(j), "00"): Next j 'formatage avec 2 chiffres pour le tri
tri s, 0, UBound(s) 'tri croissant
b(i, 0) = Join(s, ";")
Next i
Application.ScreenUpdating = False
[AX:BJ].ClearContents 'RAZ
With [BA1].Offset(, -3).Resize(ub + 1) 'décalage de 3 colonnes
.Value = b
.TextToColumns .Cells, xlDelimited, Semicolon:=True 'commande Convertir
End With
Application.ScreenUpdating = True
MsgBox ub + 1 & " lignes ont été traitées en " & Format(Timer - t, "0.00 \sec")
End Sub
Sub tri(a, gauc, droi) ' Quick sort
Dim ref, g, d, temp
ref = a((gauc + droi) \ 2)
g = gauc: d = droi
Do
Do While a(g) < ref: g = g + 1: Loop
Do While ref < 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