Hello,
I'm new to VBA and I have some code for an audit trail I've found on the web that I'd like to make work for my project.
The goal is to have 5 columns of data, on another worksheet titled "Audit", as follows: Username of who made the change, Cell change location, Previous Data, New Data (overwritten or added new), Date/Time of Change.
What is currently happening is I seem to only be tracking changes that happen in column A of my primary worksheet. It does track Username, cell location, new data, and date/time of change. But it doesn't pick up what the previous data was and I am stumped on that part. I've tried changing certain lines to different ranges and I'm not seeing any changes in what it prints out.
Here is my code just for the Audit Trail portion:
'========================================
'AUDIT TRAIL
'========================================
Dim i As Long
Dim ws As Worksheet
Set ws = Sheets("Audit")
i = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
If Target.Value <> Previous.Value Then
With ws
.Range("A" & i).Value = Application.UserName
.Range("B" & i).Value = Target.Address
.Range("C" & i).Value = Previous.Value
.Range("D" & i).Value = Target.Value
.Range("E" & i).Value = Format(Now(), "dd/mm/yyyy, hh:mm:ss")
End With
End If
PreviousValue = Target.Value
Bookmarks