Modification cellule

Bonjour,

Dans un fichier excel j'aimerais que lorsque nous entrons une date en A1 qu'automatiquement elle se change pour afficher le premier jour du mois. Exemple si on entre 3 mars 2017, le système inscrit 1 mars 2017 automatiquement.

Je n'ai aucune idée si c'est possible par contre.

Merci beaucoup.

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

WOW super !!! Maintenant si je veux que la cellule B2 fasse la même chose, comment l'ajouter à la même macro?

Merci beaucoup.

Bonjour,

à tester,

Private Sub Worksheet_Change(ByVal Target As Range)
If Application.Intersect(Target, Union(Range("A1"), Range("B2"))) Is Nothing Then Exit Sub
Application.EnableEvents = False
    If Application.IsText(Target) Or Target = 1 Or Target = 0 Or Target < 0 Then
        Target.ClearContents
        MsgBox "Vous devez entre une date valide en cellule " & Target.Address
        Range(Target.Address).ClearContents
    Else
        Range(Target.Address) = DateSerial(Year(Target), Month(Target), 1)
    End If
 Application.EnableEvents = True
End Sub

Sub AuCasOu()
Application.EnableEvents = True
End Sub

WOW merci beaucoup !!!

Rechercher des sujets similaires à "modification"