Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Application.Intersect(Target, Range("C8:I9,C12:I13,C16:I17,C41:I57")) Is Nothing Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
Dim DateStr As String
On Error GoTo EndMacro
Application.EnableEvents = False
Target.NumberFormat = "General"
If Target.HasFormula = False Then
Select Case Len(Target.Formula)
Case 3
DateStr = Left(Target.Formula, 1) & ":" & Right(Target.Formula, 2)
Case 4
DateStr = Left(Target.Formula, 2) & ":" & Right(Target.Formula, 2)
Case Else
Err.Raise 0
End Select
Target.Formula = CDate(DateStr)
Target.NumberFormat = "hh:mm"
End If
Application.EnableEvents = True
Exit Sub
EndMacro:
Target.ClearContents
Target.Select
MsgBox "Heure invalide"
Application.EnableEvents = True
End Sub