Bonjour le Forum,bonjour chris,
voici une macro qui fabrique un calendrier et qui colorie en gris (colorindex=15) les samedi,dimanches et feriés.
Sub Créa_Calendrier()
' construit un calendrier dans une ligne
' choix de la cellule de départ par l'utilisateur
' choix des dates de début et fin de calendrier
Dim deb#, fin#, NbJours&, i As Date
Dim Cell As Range, Li&, Col%
On Error Resume Next
deb = CDate(InputBox("Première date du calendrier :"))
fin = CDate(InputBox("Dernière date du calendrier :"))
If Err <> 0 Then Exit Sub
Set Cell = Cells(5, 2) 'Application.InputBox _
("Sélectionnez la cellule où commence le calendrier", Type:=8)
If Err <> 0 Then Exit Sub
Li = Cell.Row: Col = Cell.Column
For i = deb To fin
Cells(Li, Col).Value2 = i
' pour surligner les samedis, dimanches et fériés
If TYPEJOUR(i) = 1 Or TYPEJOUR(i) = 2 Then _
Cells(Li, Col).Interior.ColorIndex = 15
Cells(Li, Col).NumberFormatLocal = "jjjj jj"
Col = Col + 1
Next i
Couleur_Col
End Sub
'Cette fonction renvoie 0 si le jour passé en paramètre est un jour de semaine,
'1 s'il s'agit d'un samedi ou d'un dimanche et 2 s'il s'agit d'un jour férié.
'Valide jusqu'en 2099 et pour les jours fériés français
Function TYPEJOUR(D As Date)
Dim A As Integer, T As Integer
Dim LP As Date, LD As Long
Dim Toto As Long
A = Year(D)
If A > 2099 Then
TYPEJOUR = CVErr(xlErrValue)
Exit Function
End If
LD = Int(D)
If LD <= 2 Then
If LD = 1 Then TYPEJOUR = 2
Exit Function
End If
T = (((255 - 11 * (A Mod 19)) - 21) Mod 30) + 21
LP = DateSerial(A, 3, 2) + T + (T > 48) _
+ 6 - ((A + A \ 4 + T + (T > 48) + 1) Mod 7)
Select Case D
' Jours fériés mobiles
Case Is = LP, Is = LP + 38, Is = LP + 49
TYPEJOUR = 2
' Jours fériés fixes
Case Is = DateSerial(A, 1, 1), Is = DateSerial(A, 5, 1), _
Is = DateSerial(A, 5, 8), Is = DateSerial(A, 7, 14), _
Is = DateSerial(A, 8, 15), Is = DateSerial(A, 11, 1), _
Is = DateSerial(A, 11, 11), Is = DateSerial(A, 12, 25)
TYPEJOUR = 2
Case Else
' Samedi ou dimanche
If Weekday(D, vbMonday) >= 6 Then TYPEJOUR = 1
End Select
End Function
Bon Excel. A +
Macpoy
Fait que chaque heures de ta vie soit un souvenir pour demain!!!