Public Const Synod = 29.530588861
Public Const BaseNewMoonDateString As String = "2024-05-07 23:22"
Sub test()
Agenda 2024, 5 'année puis mois
End Sub
Function Agenda(année, mois)
Dim i As Long, l As Long, col As Long, lig As Long, nbjour As Long, j, x, k, Jférié, Jfériéstring,
Application.DisplayAlerts = False: Application.ScreenUpdating = False
With Worksheets("Feuil1")
Cells.Delete
Cells(lig, col + 1).AddComment
Cells(lig, col + 1).Comment.Text Text:="Pleine lune"
End If
If Cells(lig, col) = 4 Then
Cells(lig, col).AddComment
Cells(lig, col).Comment.Text Text:="Dernier quart de lune"
End If
col = col + 1
Next i
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'"""""""""""""""""""""""""""""""""""""""""""""""" Base jour """"""""""""""""""""""""""""""""""""""""""""""""""""""""
lig = 2: col = 2
For i = 1 To nbjour
.Cells(lig, col).Font.Size = 14
.Cells(lig - 1, col).Font.Size = 14
.Range(Cells(lig - 1, col), Cells(lig + 1, col)).Font.Bold = True
.Range(Cells(lig, col), Cells(lig + 1, col)).HorizontalAlignment = xlCenter
.Cells(lig, col) = WorksheetFunction.Proper(Format(DateSerial(année, mois, i), "dddd"))
.Cells(lig + 1, col) = (Format(DateSerial(année, mois, i), "dd" & " " & "mmmm" & " " & année))
col = col + 1
Next i
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'""""""""""""""""""""""""""""""""""""""""""" N° de semaine Fusion """"""""""""""""""""""""""""""""""""""""""""""""""
i = 1
While i <= nbjour
If i = 1 Or Weekday(DateSerial(année, mois, i), vbMonday) = 1 Then
Cells(1, 1 + i).Value = "Semaine " & Application.IsoWeekNum(DateSerial(année, mois, i))
j = i
End If
If i = nbjour Or Weekday(DateSerial(année, mois, i), vbMonday) = 7 Then
With Range(Cells(1, 1 + j), Cells(1, 1 + i))
.Merge
.HorizontalAlignment = xlCenter
End With
End If
i = i + 1
Wend
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'"""""""""""""""""""""""""""""""""""""""""""" Heures de travail """"""""""""""""""""""""""""""""""""""""""""""""""""
HdebAM = Worksheets("Paramètre").Range("C3").Value: HfinAM = Worksheets("Paramètre").Range("C4").Value
HdebPM = Worksheets("Paramètre").Range("C5").Value: HfinPM = Worksheets("Paramètre").Range("C6").Value
derlig = .Range("A" & Rows.Count).End(xlUp).Row: dercol = .Cells(2, Columns.Count).End(xlToLeft).Column
lig = 4: col = 1
For i = HdebAM To HfinAM ' Matin
.Cells(lig, col) = HdebAM
dercol)).Borders(xlEdgeBottom).LineStyle = xlContinuous
.Range(Cells(lig + 2, 2), Cells(lig + 2, dercol)).Borders(xlEdgeTop).LineStyle = xlContinuous
.Range(Cells(lig, 2), Cells(lig, dercol)).Borders(xlEdgeBottom).LineStyle = xlDot
lig = lig + 2: HdebPM = HdebPM + 1
Next
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'""""""""""""""""""""""""""""""""""""""""""" Coloriage des jours """""""""""""""""""""""""""""""""""""""""""""""""""
derlig = .Range("A" & Rows.Count).End(xlUp).Row
dercol = .Cells(2, Columns.Count).End(xlToLeft).Column
lig = 2: col = 2
For i = 1 To nbjour
'Coloriage ligne n° semaine
.Cells(lig - 1, col).Interior.ColorIndex = 20
'Coloriage jours
.Range(Cells(lig, col), Cells(lig + 1, col)).Interior.ColorIndex = 20
'Coloriage jours chomés
m = 10 ' Range G, ligne 5 dans la feuille paramètre
For h = 1 To 7 ' choix de 7 jours dans la feuille paramètre
If Worksheets("Paramètre").Range("E" & m).Value = True And Weekday(DateSerial(année, mois, i), vbMonday) = Worksheets("Paramètre").Range("F" & m).Value Then
.Range(Cells(lig, col), Cells(derlig + 1, col)).Interior.ColorIndex = 20
End If
m = m + 1
Next h
'Coloriage férié
For j = 0 To UBound(Jférié)
If CDate(Jférié(j) & année) = DateSerial(année, mois, i) Then
.Range(Cells(lig, col), Cells(derlig + 1, col)).Interior.ColorIndex = 35
Cells(lig, col).Interior.ColorIndex = 35
Cells(lig + 2, col) = Jfériéstring(j)
Cells(lig + 2, col).HorizontalAlignment = xlCenter
Cells(lig + 2, col).Font.Bold = True
End If
Next j
If année = Year(Date) And mois = Month(Date) And i = Day(Date) Then
.Range(Cells(lig, col), Cells(lig + 1, col)).Interior.ColorIndex = 28 'Coloriage aujourd'hui
'ActiveWindow.ScrollColumn = i + 1 'va à la colonne
End If
'Coloriage fête
For k = 0 To UBound(Jfete)
If CDate(Jfete(k) & année) = DateSerial(année, mois, i) Then
Cells(lig + 2, col) = Jfetestring(k)
Cells(lig + 2, col).HorizontalAlignment = xlCenter
End If
Next k
.Cells(derlig + 2, col) = "Fêtes à souhaiter" & " : "
.Cells(derlig + 2, col).Interior.ColorIndex = 36
.Cells(derlig + 2, col).Font.Size = 11
.Rows(derlig + 3).RowHeight = 80
.Cells(derlig + 3, col).HorizontalAlignment = xlCenter
.Cells(derlig + 3, col).VerticalAlignment = xlCenter
.Cells(derlig + 3, col).Font.Bold = True
col = col + 1
Next i
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'""""""""""""""""""""""""""""""""""""""""""" Quadrillage Agenda """"""""""""""""""""""""""""""""""""""""""""""""""""
.Range(Cells(2, 2), Cells(3, dercol)).Borders(xlEdgeTop).LineStyle = xlContinuous
.Range(Cells(2, 2), Cells(3, dercol)).Borders(xlEdgeLeft).LineStyle = xlContinuous
.Range(Cells(2, 2), Cells(3, dercol)).Borders(xlEdgeRight).LineStyle = xlContinuous
.Range(Cells(2, 2), Cells(3, dercol)).Borders(xlInsideVertical).LineStyle = xlContinuous
.Range(Cells(4, 2), Cells(derlig + 1, dercol)).Borders(xlEdgeLeft).LineStyle = xlContinuous
.Range(Cells(4, 2), Cells(derlig + 1, dercol)).Borders(xlEdgeRight).LineStyle = xlContinuous
.Range(Cells(4, 2), Cells(derlig + 1, dercol)).Borders(xlInsideVertical).LineStyle = xlContinuous
.Range(Cells(1, 1), Cells(derlig + 3, 1)).Interior.ColorIndex = 20 'Colonne heures
.Range(Cells(derlig + 3, 1), Cells(derlig + 3, dercol)).Interior.ColorIndex = 20 'Ligne fêtes
.Range(Cells(derlig + 2, 1), Cells(derlig + 3, dercol)).Borders(xlEdgeLeft).LineStyle = xlContinuous
.Range(Cells(derlig + 2, 1), Cells(derlig + 3, dercol)).Borders(xlEdgeRight).LineStyle = xlContinuous
.Range(Cells(derlig + 2, 1), Cells(derlig + 3, dercol)).Borders(xlInsideVertical).LineStyle = xlContinuous
.Range(Cells(derlig + 3, 1), Cells(derlig + 3, dercol)).Borders(xlEdgeBottom).LineStyle = xlContinuous
.Range(Cells(1, 2), Cells(1, dercol)).Borders(xlEdgeLeft).LineStyle = xlContinuous
.Range(Cells(1, 2), Cells(1, dercol)).Borders(xlEdgeRight).LineStyle = xlContinuous
.Range(Cells(1, 2), Cells(1, dercol)).Borders(xlInsideVertical).LineStyle = xlContinuous
.Range(Cells(1, 2), Cells(1, dercol)).Borders(xlEdgeBottom).LineStyle = xlContinuous
'"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
'"""""""""""""""""""""""""""""""""""""""""""""""" Éphéméride """"""""""""""""""""""""""""""""""""""""""""""""""""""
derlig = .Range("A" & Rows.Count).End(xlUp).Row
.Columns("A").ColumnWidth = 5
.Columns("B:AG").ColumnWidth = 20
col = 2
For i = 1 To nbjour
FetePren = ""
x = 0
Do While Range("FichFetes!C1").Offset(x, 0) <> ""
If Range("FichFetes!A1").Offset(x, 0) = i And Range("FichFetes!B1").Offset(x, 0) = mois Then
FetePren = FetePren & Range("FichFetes!C1").Offset(x, 0) & ", "
End If
x = x + 1
Loop
If FetePren <> "" Then
.Cells(derlig + 3, col) = chr(10) & Mid(FetePren, 1, Len(FetePren) - 2) & chr(10) & chr(10)
Else
.Cells(derlig + 3, col) = ""
End If
col = col + 1
Next
End With
With ActiveWindow: .SplitColumn = 1: .SplitRow = 3: End With: ActiveWindow.FreezePanes = True
End Function
Sub Actualisation()
année = Year(Date)
mois = Month(Date)
Actu_jour année, mois
End Sub
Function Actu_jour(année, mois)
Application.ScreenUpdating = False
Dim i As Long, nbjour As Long
nbjour = Day(DateSerial(année, mois + 1, 0)) ' te donne le nombre de jour dans le mois en parametre
lig = 2: col = 2
With Worksheets("Feuil1")
For i = 1 To nbjour
If année = Year(Date) And mois = Month(Date) And i = Day(Date) Then
.Range(Cells(lig, col), Cells(lig + 1, col)).Interior.ColorIndex = 28 'Coloriage aujourd'hui
ActiveWindow.ScrollColumn = i + 1 'va à la colonne aujourd'hui
End If
col = col + 1
Next i
End With
End Function
Public Function PhaseLunaire(dDate As Date) As Integer
Select Case AgeLune(dDate)
Case Is > Synod - 1 'Nouvelle lune
PhaseLunaire = 1
Case Synod / 4 - 1 To Synod / 4 '1/4 de lune
PhaseLunaire = 2
Case Synod / 2 - 1 To Synod / 2 'Pleine lune
PhaseLunaire = 3
Case 3 * Synod / 4 - 1 To 3 * Synod / 4 '3/4 de lune
PhaseLunaire = 4
Case Else 'Lune noir
PhaseLunaire = 0
End Select
End Function
Public Function AgeLune(dDate As Date) As Single
Dim BaseDate As Date
BaseDate = CDate(BaseNewMoonDateString)
AgeLune = REMAINDER((dDate - BaseDate), Synod)
End Function
Public Function REMAINDER(Number As Variant, DivideBy As _
Variant) As Variant
If Number = 0 Then REMAINDER = 0 Else REMAINDER = Number - DivideBy * Int(Number / DivideBy)
End Function