Hi, Can someone help me to correct this VBA?
I was looking for a VBA which gives auto comment when I change a value in any cell. I got a code that is more similar to my expectation.
This code is working. But in the comment, it is not showing what was the previous value.
Also, I want multiple lines of comment if the amendment was done multiple times. Also is it possible to change the default comment box size?
I added this VBA by right-clicking the sheet name>View code>and pasting this code there? Is it the correct way to do it?
File is attached here.
Thanks in Advance
I was looking for a VBA which gives auto comment when I change a value in any cell. I got a code that is more similar to my expectation.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
val_before = Target.Value
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then
MsgBox Target.Count & " cells were changed!"
Exit Sub
End If
If Target.Comment Is Nothing Then
Target.AddComment
existingcomment = ""
Else
existingcomment = Target.Comment.Text & vbLf & vbLf
End If
Target.Comment.Text Text:=Format(Now(), "DD.MM.YYYY hh:mm") & ":" & vbLf & Environ("UserName") & _
" changed " & val_before & Target.Address & " from:" & vbLf & """" & val_before & _
"""" & vbLf & "to:" & vbLf & """" & Target.Value & """"
End Sub
This code is working. But in the comment, it is not showing what was the previous value.
Also, I want multiple lines of comment if the amendment was done multiple times. Also is it possible to change the default comment box size?
I added this VBA by right-clicking the sheet name>View code>and pasting this code there? Is it the correct way to do it?
File is attached here.
Thanks in Advance