VBA Code to create an audit trail in Excel 2010

Confused_UK

Board Regular
Joined
Dec 19, 2015
Messages
56
Hi all

I am looking for some VBA code to record any changes to a workbook in one worksheet called "ChangesLog".

Ideally I would like it to show the name of the individual making the change, the date and timestamp of the change, which cell in which worksheet has been changed, and the old and new values, but in a table.

I have found the code below which works very well, but would like it broken into individual cells. Does anyone have any ideas?

Code:
[COLOR=#000000][FONT=Verdana]Dim PreviousValue[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value <> PreviousValue Then
Sheets("log").Cells(65000, 1).End(xlUp).Offset(1, 0).Value = _
Application.UserName & " changed cell " & Target.Address _
& " from " & PreviousValue & " to " & Target.Value & " at: " & Time & " on: " & Date
End If
End Sub[/FONT][/COLOR]
[COLOR=#000000][FONT=Verdana]Private Sub Worksheet_SelectionChange(ByVal Target As Range)
PreviousValue = Target.Value
End Sub[/FONT][/COLOR]

Thank you in advance
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
What was the issue incase others run into it and what did you do to resolve it?
 
Upvote 0
I realize this is a longshot because this thread is old but I'm having a similar issue with the code pasted here in that the old value isn't being pulled in. Does anyone know how to fix this?
 
Upvote 0

Forum statistics

Threads
1,214,818
Messages
6,121,725
Members
449,049
Latest member
MiguekHeka

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top