Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
[COLOR="red"]If Application.Intersect(Target, Range("C7:I8")) Is Nothing And Application.Intersect(Target, Range("C10:I11")) Is Nothing _
And Application.Intersect(Target, Range("C15:I16")) Is Nothing And Application.Intersect(Target, Range("C22:I38")) Is Nothing Then Exit Sub[/COLOR]
'If Target.Address <> "$C$7" 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 "Il faut saisir une Heure Valide" & Chr(10) & Chr(10) & "avec un format: hmm ou hhmm"
Application.EnableEvents = True
End Sub