Help me get Excel activity log to record previous value & deleted text

BonnieM

Board Regular
Joined
Nov 3, 2014
Messages
71
Hi Team,

After much searching, I found this code to create a log of user changes to an excel spreadsheet. It records when text is entered or changed, but not if deleted.

Also, it does not show the previous value - always shows as blank - it seems the error handling is resetting PreviousValue to 0

I tried going to author of code, but he hasn'et answered - can anyone here assist in recording PreviousValue AND showing when text is deleted?


Sample from current log when text is added to blank cell or new text is added:

9/2/2015 11:35:08 AMMeck, Bonnie changed cell $H$3 from to test






Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    'define variables
        Dim sLogFileName As String, nFileNum As Long, sLogMessage As String
        Dim PreviousValue
    
    'only do these things if NOT read-only
        If ThisWorkbook.ReadOnly = False Then
    
    'do not log inserting of rows or columns (as this would only be done by admin after unprotecting sheet)
        If Target.Rows.Count > 1 Then Exit Sub
        If Target.Columns.Count > 1 Then Exit Sub
    
    'define path for log file
        sLogFileName = "S:\Data Quality\SOX\ICRR Documentation\tracker test versions\Tracker Log.txt"
    
    ' Turn on error handling
        On Error Resume Next
        If Target.Value <> PreviousValue Then
    'Check if we have an error
            If Err.Number = 13 Then
            PreviousValue = 0
            End If
    'Turn off error handling
        On Error GoTo 0
        
    'define log data
        sLogMessage = Now & Application.UserName & " changed cell " & Target.Address _
        & " from " & PreviousValue & " to " & Target.Value


    'next file number
        nFileNum = FreeFile
     
    'create the file if it doesn't exist
        Open sLogFileName For Append As #nFileNum
        
    'append information
        Print #nFileNum, sLogMessage
        
    'close the file
        Close #nFileNum
    
    'if activity, reset the timer
        Monitor OnTimeAction:=xlOnTimeUpdate
    
        End If
    
Else
 
End If
        
End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim PreviousValue
    PreviousValue = Target(1).Value


'if activity, reset the timer
    Monitor OnTimeAction:=xlOnTimeUpdate


End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,216,744
Messages
6,132,470
Members
449,729
Latest member
davelevnt

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