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
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
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