Option Explicit
Function DuréeAMJH(ByVal V As Double) As String
DuréeAMJH = Décomposé(V, "365,2425: an(s);/12: mois;1: jour(s);/24: heure(s)")
End Function
Function DuréeAMSJ(ByVal V As Double) As String
DuréeAMSJ = Décomposé(V, "365,2425: an(s);/12: mois;7: semaine(s);1: jour(s)")
End Function
Function Monnaie(ByVal V As Double) As String
Monnaie = Décomposé(V, "500:(n)500€;200:(n)200€;/2:(n)100€;/2:(n)50€;20:(n)20€;/2:(n)10€;" _
& "/2:(n)5€;2:(n)2€;1:(n)1€;/2:(n)50cts;0,2:(n)20ct(s);/2:(n)10cts;/2:(n)5cts;0,02:(n)2cts;/2:(n)1ct")
End Function
Function Décomposé(ByVal Valeur As Double, ByVal Fmt As String, Optional ByVal Sép As String = ", ", _
Optional ByVal DernSép As String = " et ") As String
Dim TJn() As String, Terme As String, N As Long, TSpl() As String, ZU As String, ZT As String, Unité As Double, Nombre As Long, M As Long
On Error GoTo Er
TJn = Split(Fmt, ";")
Do:
Terme = TJn(N): TSpl = Split(Terme, ":")
ZU = TSpl(0): ZT = TSpl(1)
If Left$(ZU, 1) = "/" Then Unité = Unité / Mid$(ZU, 2) Else Unité = ZU
Nombre = Int(Valeur / Unité)
If Nombre = 0 Then
For M = N To UBound(TJn) - 1: TJn(M) = TJn(M + 1): Next M
If UBound(TJn) > 0 Then ReDim Preserve TJn(0 To UBound(TJn) - 1)
Else: ZT = Nombre & Replace$(ZT, "(s)", IIf(Nombre > 1, "s", ""))
If ZT Like "*(n)*" Then If ZT Like "1(n)*" Then ZT = Mid$(ZT, 5) Else ZT = Replace$(ZT, "(n)", "×")
TJn(N) = ZT: N = N + 1: End If
Valeur = Valeur - Nombre * Unité: Loop Until N > UBound(TJn)
If UBound(TJn) > 0 And DernSép <> Sép Then
TJn(UBound(TJn) - 1) = TJn(UBound(TJn) - 1) & DernSép & TJn(UBound(TJn))
ReDim Preserve TJn(0 To UBound(TJn) - 1): End If
Décomposé = Join(TJn, Sép)
Exit Function
Er: MsgBox Err.Description: Stop: Resume
End Function