Bonjour à tous,
J'étais parti sur un truc un peu biscornu !
Sub Formate()
Dim Lg&, i%, x%
Dim T1$, T2$, T3$, T4$, T5$
Application.ScreenUpdating = False
Lg = Range("a" & Rows.Count).End(xlUp).Row
For i = 2 To Lg
x = Len(Cells(i, "a")) 'nombre caractères
If x <= 10 And Not IsEmpty(Cells(i, "a")) Then
T1 = Right(Cells(i, "a"), 2)
T2 = Left(Mid(Cells(i, "a"), x - 3, Len(Cells(i, "a")) - 2), 2)
T3 = Left(Mid(Cells(i, "a"), x - 5, Len(Cells(i, "a")) - 4), 2)
T4 = Left(Mid(Cells(i, "a"), x - 8, Len(Cells(i, "a")) - 6), 2)
If x = 9 Then 'commence par zéro
T5 = "0" & Left(Cells(i, "a"), 1)
Else
T5 = Left(Cells(i, "a"), 2)
End If
'--- recompose ---
Cells(i, "b") = T5 & " " & T4 & " " & T3 & " " & T2 & " " & T1
Else
Cells(i, "b") = Cells(i, "a")
End If
Next i
End Sub
vba-new,
avec ta formule, on a un zéro de trop au début, çà doit pouvoir se corriger
édit: pour la formule, il faut écrire
=TEXTE(A2;"00"" ""##"" ""##"" ""##"" ""##")
Amicalement
Claude