Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim NombreJour As Integer, Pos_Esp
Dim LaDate As Date
Dim MoisSuivant As String
If Target.Count > 1 Or Sh.Name = "MENU" Then Exit Sub
If Not Intersect(Sh.Range("I1"), Target) Is Nothing Then
Inscription_Motifs
Else
Application.EnableEvents = False
NombreJour = Day(DateAdd("m", 1, DateValue(Sh.Name)) - 1)
LaDate = DateSerial(Split(Sh.Name, " ")(1), Month(DateValue(Sh.Name)), Target.Row - 5)
If Target.Row - 5 > Day(Date) And Target.Column < 5 Then
Beep
MsgBox "PAS LE BON JOUR"
Target = ""
Else
If Target.Column = 5 And Target.Row > 5 Then
If Target <> "" Then
Range("D" & Target.Row) = Application.Proper(Format(LaDate, "dddd dd mmmm yyyy"))
'Mise en forme des horaires doubles
Pos_Esp = InStr(1, Target, " ", 1) 'Recherche du caractère "Espace"
If Pos_Esp <> 0 Then ' Présence de 2 horaires
If Pos_Esp = 5 Then
Target = Left(Target, Pos_Esp - 1) & " " & Mid(Target, Pos_Esp + 1, 5)
ElseIf Pos_Esp = 6 Then '6 ou 5
Target = Left(Target, Pos_Esp - 1) & " " & Mid(Target, Pos_Esp + 1, 5)
End If
End If
Else
Application.EnableEvents = False
If Len(Target) > 5 Then
Target = Left(Target, 4) & " " & Right(Target, 4) 'Mid(Target, 5)
End If
Application.EnableEvents = True
Range("D" & Target.Row).Resize(, 4).ClearContents
If Range("A" & Target.Row) = "" Then Range("H" & Target.Row) = ""
End If
End If
If Not Intersect(Sh.Range("B6:C" & 5 + NombreJour), Target) Is Nothing Then ' Surveille la plage du 1er au dernier jours du mois
' Si la colonne B et la colonne C est vide on efface la date
Range("A" & Target.Row) = IIf(Range("B" & Target.Row) & Range("C" & Target.Row) = "", "", Application.Proper(Format(LaDate, "dddd dd mmmm yyyy")))
If Range("A" & Target.Row) <> "" Then
Range("H" & Target.Row) = LaDate
Else
Range("H" & Target.Row) = ""
End If
End If
End If
End If
Application.EnableEvents = True
End Sub