I have the following vba which simply tracks what users of the database do (For auditing reasons)
However, if I add a new line to a worksheet (quite a common event!), the routine takes an age to process this.
Is there a quicker way to do this?
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal target As Range)
Dim LR As Long
If Sh.Name = "Variations" Then Exit Sub
Application.EnableEvents = False
Application.ScreenUpdating = False 'turn off screen updating to speed things up
With Sheets("Variations")
'Unprotect sheet
.Unprotect "xxx"
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 = Environ("username")
'Protect the sheet again
.Protect "xxx"
Application.ScreenUpdating = True 'turn on screen updating
End With
Application.EnableEvents = True
End Sub
However, if I add a new line to a worksheet (quite a common event!), the routine takes an age to process this.
Is there a quicker way to do this?