Macro événementielle.

Résolu
VINCENTNINI Messages postés 10 Statut Membre -  
VINCENTNINI Messages postés 10 Statut Membre -
Bonjour,
mon problème est le suivant: je peut modifier le contenu des cellules de la colonne A de ma feuille via un choix de valeur dans une liste déroulante.
J'aimerais pouvoir conserver la valeur originale (avant modification) dans la cellule correspondante en colonne B.
J'ai une macro événementielle qui marche pour A1 avec copie en B1 mais je ne parvient pas à l'étendre à A1:A20
Pourriez vous m'aider

macro :


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Address <> "$A$1" Then Exit Sub
Dim OldVal As Variant, NewVal As Variant
Application.EnableEvents = False
NewVal = Target.Value
Application.Undo
OldVal = Target.Value
Target.Value = NewVal
Target.Offset(0, 1).Value = OldVal
Application.EnableEvents = True
End Sub


Merci d'avance



Configuration: Windows / Chrome 73.0.3683.103
A voir également:

1 réponse

f894009 Messages postés 17413 Statut Membre 1 715
 
Bonjour,

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim OldVal As Variant, NewVal As Variant
    
    If Target.Count > 1 Then Exit Sub
    If Not Application.Intersect(Target, Range("A1:A20")) Is Nothing Then
        Application.EnableEvents = False
        NewVal = Target.Value
        Application.Undo
        OldVal = Target.Value
        Target.Value = NewVal
        Target.Offset(0, 1).Value = OldVal
    End If
    Application.EnableEvents = True
End Sub
0
VINCENTNINI Messages postés 10 Statut Membre
 
Merci j'essaye demain car je ne suis pas chez moi !!!
0