VBA Timestamp Note Based on Cell Input

pure vito

Board Regular
Joined
Oct 7, 2021
Messages
183
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,

I have a VBA code here that when data is entered into a cell within the range,
It automatically adds a note with a timestamp the only issue I have here is that if data is pasted into the cells or changed it resets the note with a new timestamp,
Is their anything that can be done to change this? and allow for old notes with comments to be pasted into these cells with out it resetting and removing comments in the note?

Thanks in advance,

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   
    Dim oComment As Comment, cell As Range, strPrev As String

    If Not Intersect(Target, Columns("H:K")) Is Nothing Then

        For Each cell In Intersect(Target, Columns("H:K"))

            Set oComment = Nothing
            On Error Resume Next
                Set oComment = cell.Comment
            On Error GoTo 0

            If Not oComment Is Nothing Then
                strPrev = Mid(oComment.Text, InStr(oComment.Text, "Current value: ") + 15, 999)
                oComment.Text Text:=Format(Now, "mmm dd, yyyy  h:mm AM/PM")
                                   
                                   
            ElseIf Not IsEmpty(cell) Then
                cell.AddComment
                cell.Comment.Text Text:=Format(Now, "mmm dd, yyyy  h:mm AM/PM")
                cell.Comment.Shape.Width = 150
                cell.Comment.Shape.Height = 35
               
            End If
        Next cell
    End If
   
End Sub
 
Thank you James i'll see if I can work with this, and if you have the time i'd really appreciate if you could offer advise on the other thread I mentioned, thanks again
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Hi All can anyone help with this please I'm thankful for the help given here, but after trying to make this change myself I'm failing and lacking the skill to complete 😓
 
Upvote 0
Hi,
You can adapt the following
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim oComment As Comment, cell As Range, strPrev As String

' Adjust the cell to your own situation
' You will use cell Z1 as a Falg to say Yes or No
' With 0 Nothing will happen
' If you type 1 in cell Z1, then this macro will operate as before

If Range("Z1").Value = 0 Then Exit Sub

    If Not Intersect(Target, Columns("H:K")) Is Nothing Then
        For Each cell In Intersect(Target, Columns("H:K"))
            Set oComment = Nothing
            On Error Resume Next
                Set oComment = cell.Comment
            On Error GoTo 0
            If Not oComment Is Nothing Then
                strPrev = Mid(oComment.Text, InStr(oComment.Text, "Current value: ") + 15, 999)
                oComment.Text Text:=Format(Now, "mmm dd, yyyy  h:mm AM/PM")
            ElseIf Not IsEmpty(cell) Then
                cell.AddComment
                cell.Comment.Text Text:=Format(Now, "mmm dd, yyyy  h:mm AM/PM")
                cell.Comment.Shape.Width = 150
                cell.Comment.Shape.Height = 35
            End If
        Next cell
    End If
End Sub
 
Upvote 0
Solution
That's awesome thank you James I really did try, with this now I can perform my data transfer and after create a Macro to insert 1 into Z1 of every sheet meaning all the notes will be transferred and then the will continue to work as normal, that's great thank you very much 🙏
 
Upvote 0

Forum statistics

Threads
1,223,986
Messages
6,175,788
Members
452,670
Latest member
nogarth

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