Hello Everyone,
I have been researching writing an Audit Trail macro for Excel 2007 and between several posts in this web site and others, I came up with a macro that works for my purposes (at bottom), except for one item that might not be p0ssible to perform. I want to add a reason for the change, which preferrably pop-up at the save workbook stage and automatically go into the reason column of the "Audit Trail" worksheet for each change that was performed by that user before saving. My current macro is as follows, but I am not opposed to changing it completely if I need to to accoplish my needs:
Dim PreviousValue As Variant<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o> </o>
Private Sub Worksheet_SelectionChange(ByVal Target As Range)<o></o>
PreviousValue = Target.Value<o></o>
End Sub<o></o>
<o> </o>
Private Sub Worksheet_Change(ByVal Target As Range)<o></o>
Dim NR As Long<o></o>
If Intersect(Target, Range("A1:DW400")) Is Nothing Then Exit Sub<o></o>
With Sheets("Audit Trail")<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 = PreviousValue<o></o>
.Range("F" & NR).Value = Target.Value<o></o>
.Protect Password:="xyz"<o></o>
End With<o></o>
End Sub<o></o>
The reason would go in column G, but as I stated before, I am not married to this macro and will use anyone that works. Thank you in advance for your help.
Gene
I have been researching writing an Audit Trail macro for Excel 2007 and between several posts in this web site and others, I came up with a macro that works for my purposes (at bottom), except for one item that might not be p0ssible to perform. I want to add a reason for the change, which preferrably pop-up at the save workbook stage and automatically go into the reason column of the "Audit Trail" worksheet for each change that was performed by that user before saving. My current macro is as follows, but I am not opposed to changing it completely if I need to to accoplish my needs:
Dim PreviousValue As Variant<?xml:namespace prefix = o ns = "urn:schemas-microsoft-comfficeffice" /><o></o>
<o> </o>
Private Sub Worksheet_SelectionChange(ByVal Target As Range)<o></o>
PreviousValue = Target.Value<o></o>
End Sub<o></o>
<o> </o>
Private Sub Worksheet_Change(ByVal Target As Range)<o></o>
Dim NR As Long<o></o>
If Intersect(Target, Range("A1:DW400")) Is Nothing Then Exit Sub<o></o>
With Sheets("Audit Trail")<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 = PreviousValue<o></o>
.Range("F" & NR).Value = Target.Value<o></o>
.Protect Password:="xyz"<o></o>
End With<o></o>
End Sub<o></o>
The reason would go in column G, but as I stated before, I am not married to this macro and will use anyone that works. Thank you in advance for your help.
Gene