Hi,
I need to add some functions to your Audit Trail macro. I added 2 functions already (worksheet name and data entered), but I need to add the previous data a reason for change (with a pop-up in the worksheet requesting the reason with a field in the pop-up for entering the reason, is possible). I found this macro, but I can't get it to apply PreviousValue to you macro:
Dim PreviousValue<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o
></o
>
Private Sub Worksheet_Change(ByVal Target As Range)<o></o>
If Target.Value <> PreviousValue Then<o></o>
Sheets("log").Cells(65000, 1).End(xlUp).Offset(1, 0).Value = _<o></o>
Application.UserName & " changed cell " & Target.Address _<o></o>
& " from " & PreviousValue & " to " & Target.Value<o></o>
End If<o></o>
End Sub<o></o>
<o
></o
>
Private Sub Worksheet_SelectionChange(ByVal Target As Range)<o></o>
PreviousValue = Target.Value<o></o>
End Sub
This is how I have modified your macro to give me the worksheet name and data entered:
Private Sub Worksheet_Change(ByVal Target As Range)<o></o>
Dim NR As Long<o></o>
Dim PreviousValue<o></o>
If Intersect(Target, Range("A1:DW400")) Is Nothing Then Exit Sub<o></o>
With Sheets("log")<o></o>
.Unprotect Password:="xyz"<o></o>
NR = .Range("A" & Rows.Count).End(xlUp).Row + 1<o></o>
.Range("A" & NR).Value = Target.Address(False, False)<o></o>
.Range("B" & NR).Value = ActiveSheet.Name<o></o>
.Range("C" & NR).Value = Now<o></o>
.Range("D" & NR).Value = Environ("username")<o></o>
.Range("E" & NR).Value = Target.Value<o></o>
.Protect Password:="xyz"<o></o>
End With<o></o>
End Sub<o></o>
<o
></o
>
<o
></o
>
Private Sub Worksheet_SelectionChange(ByVal Target As Range)<o></o>
<o
></o
>
End Sub
<o></o>
,which gives me in the "log" worksheet in columns A, B, C, D & E:
<TABLE style="WIDTH: 317pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=422><COLGROUP><COL style="WIDTH: 48pt" span=2 width=64><COL style="WIDTH: 125pt; mso-width-source: userset; mso-width-alt: 6070" width=166><COL style="WIDTH: 48pt" span=2 width=64><TBODY><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 48pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl65 height=20 width=64>
I25</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl65 width=64>
Sheet1</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 125pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl66 width=166>
10/4/2011 14:11</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl65 width=64>
eherron</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 48pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl65 width=64>
559</TD></TR><TR style="HEIGHT: 15pt" height=20><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl65 height=20>
C18</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl65>
Sheet1(2)</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl66>
10/4/2011 14:12</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl65>
eherron</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" class=xl65>
126</TD></TR></TBODY></TABLE>
I tried entering
.Range("E" & NR).Value = Target.PreviousValue and .Range("E" & NR).Value = Target.PreviousValue with .Range("F" & NR).Value = Target.Value, but neither worked. Any ideas on how to make this work?
I could find nothing for adding a reason.