I have an audit log VBA code, to capture changes from several worksheets into one worksheet called "LRLog".
This only writes value changes. Formatting changes are not required to be captured.
The VBA code works fine, but does NOT capture changes in those cells which are determined by IF formula based on data input in other cells.
Users will make changes in columns C, D, E, F, and H, with IF formula in columns A and G showing a result, dependent on the data input in columns D, E, and F.
However, currently, any changes to cols A or G (because of the outcome of formulae in col A or G) are not captured in the audit log, as attached:
(yellow blocks in the attached Audit log are what is expected should be displayed).
The following VBA has been used in the sheets where changes will take place.
------------------------------------------
Dim PreviousValue As Variant
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Errb As Integer
On Error GoTo ErrTrap:
If Target.Value <> PreviousValue Then
With Sheets("LRlog").Cells(65000, 1).End(xlUp)
.Offset(1, 0).Value = Application.UserName
.Offset(1, 1).Value = ActiveSheet.Name
.Offset(1, 2).Value = "changed cell"
.Offset(1, 3).Value = Target.Address
.Offset(1, 4).Value = "from"
.Offset(1, 5).Value = PreviousValue
.Offset(1, 6).Value = "to"
.Offset(1, 7).Value = Target.Value
.Offset(1, 8).Value = "on"
.Offset(1, 9).Value = Format(Date, "d/mmm/yyyy")
.Offset(1, 10).Value = Format(Now(), "hh:mm:ss")
End With
End If
Exit Sub
ErrTrap:
ErrNum = Err
If ErrNum = 13 Then
'*** Multiple cells have been selected, treat them as one merged group*****
Resume Next
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
PreviousValue = Target.Value
End Sub
------------------------------------
Can anyone help with the VBA code so that any changes to cols A or G (because of the outcome of formulae in col A or G) are also captured in the audit log?
I would also like to include good error handling in this project if possible.
Bookmarks