Sub Coloriage()
'Déclaration de constantes : à chaque mois une couleur
Const Jan = 4
Const Fev = 5
Const Mar = 6
Const Avr = 7
Const Mai = 8
Const Jun = 9
Const Jul = 10
Const Aou = 11
Const Sep = 12
Const Oct = 13
Const Nov = 14
Const Dec = 15
'Déclaration de 2 variables (n= nombre de lignes du tableau, i = boucle sur chaque ligne)
Dim n&, i&
'Déclaration d'une variable numérique correspondant au mois
Dim M As Byte
'Trouve la dernière ligne écrite de la colonne A = nbre ligne du tableau
n = Cells(65536, 1).End(3).Rows
'Passe en boucle sur chaque ligne
For i = 4 To n
'Si la valeur en D est une date
If IsDate(Cells(i, 4)) Then
'M= la valeur du mois
M = Month(Cells(i, 4))
'En fonction de la valeur du mois, on affecte la couleur désignée
Select Case M
Case 1
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = Jan
Case 2
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = Fev
Case 3
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = Mar
Case 4
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = Avr
Case 5
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = Mai
Case 6
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = Jun
Case 7
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = Jul
Case 8
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = Aou
Case 9
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = Sep
Case 10
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = Oct
Case 11
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = Nov
Case 12
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = Dec
End Select
'Si la valeur de la colonne D n'est pas une date, alors pas de couleur
Else
Range(Cells(i, 1), Cells(i, 9)).Interior.ColorIndex = 0
End If
Next i
End Sub
' + un bouton qui lance la macro
Private Sub CommandButton1_Click()
Coloriage
End Sub