Ambiguous name detected: worksheet_change en VBA excel

Résolu/Fermé
Dianex87 Messages postés 79 Date d'inscription jeudi 9 mars 2017 Statut Membre Dernière intervention 8 août 2017 - 10 mars 2017 à 14:46
Dianex87 Messages postés 79 Date d'inscription jeudi 9 mars 2017 Statut Membre Dernière intervention 8 août 2017 - 14 mars 2017 à 11:14
Bonjour,

J'ai sur le même Worksheet les 2 macro suivantes :

Private Sub Worksheet_Change(ByVal sel As Range)
'Column A is autofilled with the date of the last line update
If sel.Row > 2 Then
Application.EnableEvents = False
Cells(sel.Row, "A").Value = Date
Application.EnableEvents = True
End If
End Sub

ET

Private Sub Worksheet_Change(ByVal Target As Range)
'When a new row is created, column B is autofilled with the creation of the date
Range("B" & Target.Row).Value = Now
End Sub

Et les 2 ne peuvent visiblement pas fonctionner car étant sur le meme sheet; j'ai le message suivant: Ambiguous name detected worksheet_change.

J'ai besoin des 2; quelqu'un aurait-il la solution SVP?

Merci bcp,
Dianex

1 réponse

cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 728
10 mars 2017 à 15:38
bonjour,

comme ceci:

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim changement As Boolean
If Target.Rows(1).Cells.Count = Columns.Count Then changement = True
If Target.Columns(1).Cells.Count = Rows.Count Then changement = True
If changement = True Then
Range("B" & Target.Row).Value = Now
End If
If Target.Row > 2 Then
Application.EnableEvents = False
Cells(Target.Row, "A").Value = Date
Application.EnableEvents = True
End If
End Sub

0
Dianex87 Messages postés 79 Date d'inscription jeudi 9 mars 2017 Statut Membre Dernière intervention 8 août 2017
14 mars 2017 à 11:14
Mille mercis de ton aide sur mes 2 sujets !!
Cela fonctionne
0