Hello, I am trying to find a way how I can log all changes made to the workbook.
I have found a perfect piece of code on a forum thread here.
I will link the code:
I have an extra sheet called "Log" which you will need as well if you want to test this.
I need help improving this code. The code breaks when I try to move a cell or when I copy past information it does not record the changes made.
Could someone give me a hand to try and improve the code to track these changes it would of great help.
Thanks!
I have found a perfect piece of code on a forum thread here.
I will link the code:
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim LR As Long, X As Variant
If Sh.Name = "Log" Then Exit Sub
If Target.HasFormula Then Exit Sub
X = Target.Value
With Application
.EnableEvents = False
.ScreenUpdating = False
If Target.Count = 1 Then .Undo
End With
With Sheets("Log")
.Unprotect Password:="pw"
LR = .Range("A" & Rows.Count).End(xlUp).Row
.Range("A" & LR + 1).Value = Now
.Range("B" & LR + 1).Value = Sh.Name
.Range("C" & LR + 1).NumberFormat = "@"
.Range("C" & LR + 1).Value = Target.Address(False, False)
.Range("D" & LR + 1).Value = Target.Value
.Range("E" & LR + 1).Value = X
.Range("F" & LR + 1).Value = Environ("username")
.Protect Password:="pw"
End With
If Target.Count = 1 Then Target.Value = X
On Error Resume Next
Target.Offset(, 1).Select
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
I have an extra sheet called "Log" which you will need as well if you want to test this.
I need help improving this code. The code breaks when I try to move a cell or when I copy past information it does not record the changes made.
Could someone give me a hand to try and improve the code to track these changes it would of great help.
Thanks!