Re,
Voilà le code qui ne marche pas
Private Sub Workbook_Sheetchange(ByVal feuille As Object, ByVal cible As Range)
Dim avant() As Variant, apres() As Variant
On Error GoTo fin
If feuille.Name = "journal" Then Exit Sub
If feuille.Name = "TDB" Then Exit Sub
If cible.Columns.Count = Columns.Count Or cible.Rows.Count = Rows.Count Then
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
MsgBox "Impossible d'agir sur une ligne ou une colonne complète !"
Exit Sub
End If
Application.EnableEvents = False
ReDim avant(1 To cible.Rows.Count, 1 To cible.Columns.Count)
ReDim apres(1 To cible.Rows.Count, 1 To cible.Columns.Count)
Application.Undo
For lig = 1 To UBound(avant)
For col = 1 To UBound(avant, 2)
avant(lig, col) = cible.Cells(1, 1).Offset(lig - 1, col - 1).FormulaLocal
Next
Next
Application.Undo
For lig = 1 To UBound(apres)
For col = 1 To UBound(apres, 2)
apres(lig, col) = cible.Cells(1, 1).Offset(lig - 1, col - 1).FormulaLocal
Next
Next
For lig = 1 To cible.Rows.Count
For col = 1 To cible.Columns.Count
If avant(lig, col) <> apres(lig, col) Then
With Sheets("journal").ListObjects(1)
.ListRows.Add
i = .ListRows.Count
With .DataBodyRange
.Cells(i, 1) = Now
.Cells(i, 2) = feuille.Name
.Cells(i, 3) = cible.Cells(1, 1).Offset(lig - 1, col - 1).Address
.Cells(i, 4) = "'" & avant(lig, col)
.Cells(i, 5) = "'" & apres(lig, col)
.Cells(i, 6) = Environ("username")
End With
End With
End If
Next
Next
fin:
Application.EnableEvents = True
If Err Then MsgBox "Erreur #" & Err.Number & " !"
End Sub