Good morning Mr Excel Forum,
Thanks in advance everybody for reading, helping, advicing.
i am looking to track changes in an excel sheet in a non-shared workbook. The old value should be written to the cell's comment on top of the previous tracking comment. It is supposed to not be modified by users. Unfortunately i receive an error runtime 91.
example of required comment :
Previous Value was azer
Revised 09-07-2017
By Yan
Previous Value was YRZX
Revised 03-07-2017
By Cin
Here is the code I added:
Option Explicit
Public VolDvaL As Variant
Public preValue As Variant
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Target.ClearComments
Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10) & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " & Environ("UserName") & VolDvaL
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target = "" Then
preValue = "a blank"
Else: preValue = Target.Value
End If
If Target.Comment.Text = "" Then
VolDvaL = ""
Else: VolDvaL = Target.Comments
End If
End Sub
I assume there is some information missing like " how to protect the comment from modification" and "how to add the previous value saved" but I am pretty sure somebody here will find how to insert this in the upper code
Many thanks in advance for your kind assistance.
Yaninja
Thanks in advance everybody for reading, helping, advicing.
i am looking to track changes in an excel sheet in a non-shared workbook. The old value should be written to the cell's comment on top of the previous tracking comment. It is supposed to not be modified by users. Unfortunately i receive an error runtime 91.
example of required comment :
Previous Value was azer
Revised 09-07-2017
By Yan
Previous Value was YRZX
Revised 03-07-2017
By Cin
Here is the code I added:
Option Explicit
Public VolDvaL As Variant
Public preValue As Variant
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
Target.ClearComments
Target.AddComment.Text Text:="Previous Value was " & preValue & Chr(10) & "Revised " & Format(Date, "mm-dd-yyyy") & Chr(10) & "By " & Environ("UserName") & VolDvaL
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target = "" Then
preValue = "a blank"
Else: preValue = Target.Value
End If
If Target.Comment.Text = "" Then
VolDvaL = ""
Else: VolDvaL = Target.Comments
End If
End Sub
I assume there is some information missing like " how to protect the comment from modification" and "how to add the previous value saved" but I am pretty sure somebody here will find how to insert this in the upper code
Many thanks in advance for your kind assistance.
Yaninja