Option Explicit
Function PremiereValeurMois(ZoneDate As Range, ZoneMontant As Range, MoisNumerique As Byte) As Currency
Application.Volatile
Dim Cellule As Range
Dim Montant As Currency
Dim Jour As Byte
If ZoneDate.Row <> ZoneMontant.Row Then
PremiereValeurMois = "Erreur"
Exit Function
End If
If ZoneDate.Count <> ZoneMontant.Count Then
PremiereValeurMois = "Erreur"
Exit Function
End If
PremiereValeurMois = 0
For Each Cellule In ZoneDate
If IsDate(Cellule) Then
If Month(Cellule) = MoisNumerique Then
If Jour = 0 Then
Jour = Day(Cellule)
Montant = Cellule.Offset(0, ZoneMontant.Column - Cellule.Column)
Else
If Year(Cellule) < Jour Then
Jour = Day(Cellule)
Montant = Cellule.Offset(0, ZoneMontant.Column - Cellule.Column)
End If
End If
End If
End If
Next Cellule
PremiereValeurMois = Montant
End Function
Function DerniereValeurMois(ZoneDate As Range, ZoneMontant As Range, MoisNumerique As Byte)
Dim Cellule As Range
Dim Montant As Currency
Dim Jour As Byte
Application.Volatile
If ZoneDate.Row <> ZoneMontant.Row Then
DerniereValeurMois = "Erreur"
Exit Function
End If
If ZoneDate.Count <> ZoneMontant.Count Then
DerniereValeurMois = "Erreur"
Exit Function
End If
DerniereValeurMois = 0
For Each Cellule In ZoneDate
If IsDate(Cellule) Then
If Month(Cellule) = MoisNumerique Then
If Jour = 0 Then
Jour = Day(Cellule)
Montant = Cellule.Offset(0, ZoneMontant.Column - Cellule.Column)
Else
If Year(Cellule) > Jour Then
Jour = Day(Cellule)
Montant = Cellule.Offset(0, ZoneMontant.Column - Cellule.Column)
End If
End If
End If
End If
Next Cellule
DerniereValeurMois = Montant
End Function