automatic logging of changes to spreadsheet?

jayd4wg

Board Regular
Joined
Mar 25, 2005
Messages
197
I have a public spreadsheet and want to track changes to it.

I was thinking about having a protected hidden sheet to store login name from the system and date/time of the change, and if possible what line was edited.

Is this possible?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I would take a look at the Shared workbook Functionalty under Tools->Share Workbook.

What I've done in the past is
1) Select Ranges that users can edit
2) Under the Permissions select which users can edit
3) protect the entire sheet
4) Turn on Sharing.

Then you can go into the Track Changes and on the History Tab you get a full report of what was changed, when and by who.

HTH,
CT
 
Upvote 0
What I have done is to use worksheet_selectionchange and worksheet_change events to record changes to a cell Comment.

However, as jayd4wg notes below, this is not the solution if you don't want the users to know they're being audited.

worksheet_selectionchange is used to capture the current ('old') value of the cell in case it's then modified. For simplicity I forced a check that only one cell was selected, but this could be extended to handle multiple selections, I'm sure.

worksheet_change is used to compare old and new values of the cell, and append the change history to the cell comment (first creating one if none exists).

I've used this approach, adpated from John Walkenbach's site, on a RAG (Traffic Light) chart to show how the value of the elements of the chart have changed over time. The original also include code (in AuditTheChange) to add a flag to the changed cell value to show how it had moved (↑↓↔) compared to the previous value.

Code example (all in Worksheet Code page):
Rich (BB code):
Public RAGenabled As Boolean
Dim OldVal As String
Private Const lDelim As String = "("
Private Const rDelim As String = ")"

Private Sub cbRAGenabled_Click() 
' A checkbox on the worksheet  that controls whether the auditing is done or not
    RAGenabled = cbRAGenabled.Value
    If RAGenabled = True Then
        MsgBox "RAG checking enabled"
    Else
        MsgBox "RAG checking disabled"
    End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
'
' Determines whether the range (cell) that was changes is one I want to audit (and only if auditing is ON)
'
    If RAGenabled = True Then   'Only bother if RAG checking is toggled ON
        Application.EnableEvents = False  ' prevent recursive worksheet_change events
        If Not (Application.Intersect(Target, Range("MyRange")) Is Nothing) Then ' Process if selection is in MyRange range
            Call AuditTheChange(ByVal Target)
        End If
        ' If selection is not in MyRange ranges, ignore it
        Application.EnableEvents = True ' re-enable events
    End If
'
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
'
    RAGenabled = cbRAGenabled.Value 'ensure current value, esp. first time through
    If RAGenabled = True Then   'Only check if RAG checking is toggled ON
        If (Application.Intersect(Target, Range("MyRange")) Is Nothing) Then ' is it in MyRange?
            'MsgBox "Selected cell is not within an appropriate range"    ' For debugging purposes only
            Exit Sub 'if it's not in a range to be audited, do nowt
        Else 'it is, so ...
            If Target.Count = 1 Then ' is only one cell selected?
                OldVal = Target.Value
                'MsgBox "OldVal='" & OldVal & "'"   ' For debugging purposes only
            Else
                MsgBox "Multiple selections can't be processed - select one cell at a time"
            End If
        End If
    End If
'
End Sub

'The cell value is stored in a public variable when a cell is selected (Worksheet_SelectionChange procedure).
'Then, when a new value is added, the Worksheet_Change event procedure adds a cell comment
'(the error generated if the cell already has a comment is stepped over) and then uses the stored variable
'as part of the text string for the comment, building up a change history over time.
'Adapted from http://www.j-walk.com/ss/excel/eee/eee014.txt

Sub AuditTheChange(ByVal Target As Range)
'
    If Target.Count = 1 Then ' check is only one cell selected?
        ' record a change in a comment box
        On Error Resume Next    ' Ignore the error if you have previously ....
        Target.AddComment       ' added comment box
        Target.Comment.Text Target.Comment.Text & "Whatever you want the audit text to be"
        Target.Interior.Pattern = xlSolid
        With Target.Font
             .Name = "Arial" 
             .Size = 10
             .Strikethrough = False
             .Superscript = False
             .Subscript = False
             .OutlineFont = False
             .Shadow = False
             .Underline = xlUnderlineStyleNone
             .ColorIndex = xlAutomatic
        End With
        OldVal = Target.Value    ' reset OldVal in case the selection is not changed before the cell value is changed again                      
    End If
End Sub
 
Upvote 0
that is a thing of beauty. That is EXACTLY what I wanted...and to think it's a built in function of Excel. I love this app more and more every day ;)
 
Upvote 0
GladToBeGrey said:

That wouldn't work for me for one simple reason...I don't want the editors of the sheet to know they are being audited. Few here are smart enough to even notice that the sheet is now marked as "shared" or what that even means.
 
Upvote 0

Forum statistics

Threads
1,215,011
Messages
6,122,677
Members
449,092
Latest member
tayo4dgacorbanget

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