Ambiguous name detected: worksheet_change en VBA excel

Résolu
Dianex87 Messages postés 79 Statut Membre -  
Dianex87 Messages postés 79 Statut Membre -
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

  1. cs_Le Pivert Messages postés 8437 Statut Contributeur 730
     
    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
    1. Dianex87 Messages postés 79 Statut Membre
       
      Mille mercis de ton aide sur mes 2 sujets !!
      Cela fonctionne
      0