1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
Private Sub Workbook_Sheetchange(ByVal feuille As Object, ByVal cible As Range)
Dim avant() As Variant, apres() As Variant, FA() As Variant, nFA As Variant
On Error GoTo fin
If feuille.Name = "Journal" 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)
ReDim FA(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
FA(lig, col) = cible.Cells(lig, 2)
nFA = cible.Cells(1, 1)
MsgBox FA(lig, col)
MsgBox nFA
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
Worksheets("Journal").Unprotect "CPIRE"
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")
.Cells(i, 7) = "'" & FA(lig, col)
End With
End With
End If
Next
Next
fin:
Application.EnableEvents = True
If Err Then MsgBox "Erreur #" & Err.Number & " !"
Worksheets("Journal").Protect "CPIRE", True, True, True
End Sub |
Partager