1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| Function RmbtMensuel(ThisMonth As Date, SubStartDate As Date, SubEndDate As Date, TotalSub As Currency) As Currency
Dim nbrMoisComplet&, nbrJour1&, nbrJour2&, parJour@, parMois@, Avant@, Apres@
nbrMoisComplet = DateDiff("m", SubStartDate, SubEndDate + 1)
If Day(SubStartDate) > 1 Then
nbrJour1 = Application.WorksheetFunction.EoMonth(SubStartDate, 0) - SubStartDate + 1
nbrMoisComplet = nbrMoisComplet - 1
Else
nbrJour1 = 0
End If
If Day(SubEndDate) = Day(Application.WorksheetFunction.EoMonth(SubEndDate, 0)) Then
nbrJour2 = 0
Else
nbrJour2 = Day(SubEndDate)
End If
parJour = TotalSub / (nbrJour1 + nbrJour2 + 30 * nbrMoisComplet)
parMois = Round(30 * parJour, 2)
Avant = Round(nbrJour1 * parJour, 2)
Apres = TotalSub - nbrMoisComplet * parMois - Avant
'Debug.Print nbrMoisComplet, nbrJour1, nbrJour2
If Format(ThisMonth, "yymm") = Format(SubStartDate, "yymm") Then
RmbtMensuel = IIf(nbrJour1 = 0, parMois, Avant)
ElseIf Format(ThisMonth, "yymm") = Format(SubEndDate, "yymm") Then
RmbtMensuel = IIf(nbrJour2 = 0, parMois, Apres)
Else
If (Format(ThisMonth, "yymm") >= Format(SubStartDate, "yymm")) And (Format(ThisMonth, "yymm") <= Format(SubEndDate, "yymm")) Then RmbtMensuel = parMois
End If
End Function |
Partager