G
Guest
Dear experts,
I have a code that uses the Worksheet_Change event to insert a comment
object in the changed cell with the name of the user and the date.
I have noticed, though, that if users drag and drop a cell onto a second
one, VBA considers that the 2 cells have been changed (as target), when in
reality only the second one has been changed!
Is there something I can do about this? My code is below.
Many thanks,
best regards,
Valeria
Private Sub Worksheet_Change(ByVal Target As Range)
Dim vvvrange As Range
Dim cell As Object
Set vvvrange = Range("Comment_Input")
Application.EnableEvents = False
On Error Resume Next
For Each cell In Target
If Union(cell, vvvrange).Address = vvvrange.Address Then
cell.Comment.Delete
cell.AddComment
cell.Comment.Visible = False
cell.Comment.Text Text:=Application.UserName & Chr(10) & Format(Date,
"DD-MMM-YYYY")
cell.Comment.Shape.TextFrame.AutoSize = True
End If
Next cell
On Error GoTo 0
Application.EnableEvents = True
I have a code that uses the Worksheet_Change event to insert a comment
object in the changed cell with the name of the user and the date.
I have noticed, though, that if users drag and drop a cell onto a second
one, VBA considers that the 2 cells have been changed (as target), when in
reality only the second one has been changed!
Is there something I can do about this? My code is below.
Many thanks,
best regards,
Valeria
Private Sub Worksheet_Change(ByVal Target As Range)
Dim vvvrange As Range
Dim cell As Object
Set vvvrange = Range("Comment_Input")
Application.EnableEvents = False
On Error Resume Next
For Each cell In Target
If Union(cell, vvvrange).Address = vvvrange.Address Then
cell.Comment.Delete
cell.AddComment
cell.Comment.Visible = False
cell.Comment.Text Text:=Application.UserName & Chr(10) & Format(Date,
"DD-MMM-YYYY")
cell.Comment.Shape.TextFrame.AutoSize = True
End If
Next cell
On Error GoTo 0
Application.EnableEvents = True