Bonjour,
voici un exemple,
Private Sub Worksheet_Change(ByVal Target As Range)
If Application.Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
Application.EnableEvents = False
If IsDate(Target) Then
Range("A1") = DateSerial(Year(Target), Month(Target), 1)
Else
MsgBox "Vous devez entre une date valide en cellule A1"
Range("A1").ClearContents
End If
Application.EnableEvents = True
End Sub
ÉDIT:
modification: je n'avais pas inclus toutes les possibilités
Private Sub Worksheet_Change(ByVal Target As Range)
If Application.Intersect(Target, Range("A1")) Is Nothing Then Exit Sub
If Application.IsText(Target) Or Target = 1 Or Target = 0 Or Target < 0 Then Range("A1").ClearContents: Exit Sub
Application.EnableEvents = False
Range("A1") = DateSerial(Year(Target), Month(Target), 1)
Application.EnableEvents = True
End Sub