Trace any change on sheet using Excel Comments

bennyys

New Member
Joined
Jun 22, 2017
Messages
17
Hi All,
At the moment I am working on how to track any change on cells by using comments.
I got this code for track the change on a sheet

Code:
'Track/Report User Changes on 1 Particular Worksheet. _
 The code below must be placed in the Private Module of the Worksheet you would like changes tracked and logged.


Dim vOldVal    'Must be at top of module
Dim x As String


Private Sub Worksheet_Change(ByVal Target As Range)
Dim bBold As Boolean


If Target.Cells.Count > 1 Then Exit Sub


On Error Resume Next
With Application
    .ScreenUpdating = False
    .EnableEvents = False
End With


If IsEmpty(vOldVal) Then vOldVal = "Empty Cell"
bBold = Target.HasFormula
With ActiveSheet
    Dim a As String
    Dim y As String
    Dim z As String
    z = ActiveCell.Value
    'x = GetSetting("LastComment", "Variables", "x")
    'x = Application.InputBox("Enter text", "Enter Comment", x)
    'SaveSetting "LastComment", "Variables", "x", x
'MsgBox x 'for testing
    With Range(x)
        If .Comment Is Nothing Then
            .AddComment.Text Text:=Application.UserName & vbLf & _
                    "CELL CHANGED " & Range(x).Address & ", OLD VALUE " & _
                    vOldVal & ", NEW VALUE " & Range(x).Value & _
                    ", DATE\TIME OF CHANGE " & Now()
        Else
            a = .Comment.Text
            .Comment.Delete
            .AddComment.Text Text:=a & vbLf & Application.UserName & vbLf & _
                    "CELL CHANGED " & Range(x).Address & ", OLD VALUE " & _
                    vOldVal & ", NEW VALUE " & Range(x).Value & _
                    ", DATE\TIME OF CHANGE " & Now()
        End If
        .Comment.Shape.TextFrame.AutoSize = True
    End With


    '.Cells.Columns.AutoFit
    '.Protect Password:="Secret"
End With
vOldVal = vbNullString
With Application
    .ScreenUpdating = True
    .EnableEvents = True
End With


On Error GoTo 0
End Sub


Public Sub Worksheet_SelectionChange(ByVal Target As Range)
vOldVal = Target
x = ActiveCell.Address
End Sub

As of now I put this code on every sheet code to track the change on every sheet.


My question is:
Is there a way so this code is only once written and it will work for all sheets in a workbook?
I just tried to put the code in "ThisWorkbook" code but I knew that there are some modification need to be done to get it work and I need help on this part.
Thank you in advanced.


Regards,
Benny
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,215,829
Messages
6,127,130
Members
449,361
Latest member
VBquery757

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