Sub test()
testing "1"
testing "22"
testing "8739"
testing 5378745
End Sub
Function testing(chaine As String)
chaine = Trim(Replace(Format("000" & chaine, Application.Rept("000 ", Len(chaine))), "000 ", ""))
Debug.Print chaine
End Function
001
022
008 739
005 378 745
Function testing(chaine As String)
chaine = LTrim(Format(chaine, Application.Rept("\ 000", 1 + Int((Len(chaine) - 1) / 3))))
Debug.Print chaine
End Function
Function testing(chaine As String)
chaine = LTrim(Format(chaine, Application.Rept("\ 000", 1 + Int((Len(chaine) - 1) / 3))))
Debug.Print chaine
End Function
Function testing2(chaine As String) As String
testing2 = String(3 - Len(Format(chaine, "#,##0")) Mod 4, "0") & Format(chaine, "#,##0")
Debug.Print testing2
End Function
Function testing2(chaine As String) As String
'testing2 = Left("000", 2 - (Len(chaine) - 1) Mod 3) & Format(chaine, "#,##0")
testing2 = String(2 - (Len(chaine) - 1) Mod 3, "0") & Format(chaine, "#,##0")
Debug.Print testing2
End Function
Function Testing(Chaine As String)
Testing = Right(Format(Chaine, "#,##0"), Round((4 * Len(Chaine) - 1) / 3, 0))
Debug.Print Testing
End Function
Function Testing(Chaine As String)
Testing = Right(Format(Chaine, "#,##0"), (4 * Len(Chaine) - 1) / 3)
Debug.Print Chaine
End Function
Function TestingSylvanu(chaine As String)
TestingSylvanu = Right(Format(chaine, "#,##0"), (4 * Len(chaine) - 1) / 3)
Debug.Print Right(Format(chaine, "#,##0"), (4 * Len(chaine) - 1) / 3)
End Function
Sub test()
TestingSylvanu "1"
TestingSylvanu "10"
TestingSylvanu "100"
TestingSylvanu "1000"
TestingSylvanu "10000"
TestingSylvanu "100000"
TestingSylvanu "1000000"
TestingSylvanu "1000000000"
End Sub
1
10
100
1 000
10 000
100 000
1 000 000
1 000 000 000
C'est toi qui dérailles !non les solutions 1 et 2 de @Dudu2 déraillent aussi
Function TestingSylvanu(chaine As String)
TestingSylvanu = Right(Format(chaine, "000 000 000"), Choose(Len(chaine), 3, 3, 3, 7, 7, 7, 11, 11, 11))
End Function