Public Function PlafondSS(brut As Double, deb As Date, fin As Date) As Double
Dim plafMensuel As Double
Dim Année As Long
Dim mois As Long, nbjoursMois As Long
Dim debMois As Date, finMois As Date
Dim debPer As Date, finPer As Date
Dim nbjoursPer As Long
Dim brutPlafonné As Double
Dim brutPer As Double
plafMensuel = [pm]
Année = Year(deb)
brutPlafonné = Application.Min(brut, plafMensuel)
PlafondSS = 0
For mois = 1 To 12
If mois >= Month(deb) And mois <= Month(fin) Then
debMois = DateSerial(Année, mois, 1)
finMois = DateSerial(Année, mois + 1, 0)
nbjoursMois = finMois - debMois + 1 'Nombre de jours total dans le mois
debPer = Application.Max(debMois, deb)
finPer = Application.Min(finMois, fin)
nbjoursPer = finPer - debPer + 1
brutPer = brutPlafonné / nbjoursMois * nbjoursPer
PlafondSS = PlafondSS + brutPer
End If
Next mois
End Function