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 29 30 31 32 33
| Sub Test()
Dim DerLig As Long
Dim Plage As Range, Cel As Range
With Worksheets("Feuil1") 'A adapter
DerLig = .Cells(.Rows.Count, 1).End(xlUp).Row
Set Plage = Range("E10:E" & DerLig)
For Each Cel In Plage
If IsDate(Cel) And IsDate(Cel.Offset(0, 1)) Then
If MonTest(Cel, Cel.Offset(0, 1)) Then
Cel.Resize(1, 2).Interior.ColorIndex = 28
End If
End If
Next Cel
End With
End Sub
Private Function MonTest(ByVal DteDeb As Date, DteFin As Date) As Boolean
Dim S As Boolean
'Compare si DteDeb < DteFin
S = DteDeb < DteFin
'Compare si dteDeb est le début du mois et DteFin est le dernier jour du mois
S = S And Day(DteDeb) = 1 And Month(DteFin + 1) <> Month(DteFin)
'Compare si DteDeb ou DteFin n'est pas aujourdhui
S = S And DteDeb <> Date And DteFin <> Date
'Compare si DteDeb apprtiennent au même mois
S = S And Month(DteDeb) = Month(DteFin)
'Compare si DteDeb apprtiennent à la même année
S = S And Year(DteDeb) = Year(DteFin)
'Résultat des différentes comparaisons
MonTest = S
End Function |