2016 Excel - Automatic date and time when you insert a comment

Terrifro

New Member
Joined
Jul 18, 2018
Messages
12
Office Version
  1. 2016
Platform
  1. Windows
I am currently using 2016 Excel and I want to add an automatic Date and Time when I insert a comment in a cell.

Does anyone have a code that can be insert in the spreadsheet, or is it easier then that.

Please help.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Keyboard shortcut for adding the date is Ctrl+; to add time use Shift + Ctrl + ;
 
Upvote 0
Goes in SHEET code (not a module)
Double click in cell to add the comment
click in any other cell to make it non-visible

VBA Code:
Option Explicit
Private tCell As Range
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
On Error Resume Next
    Set tCell = Target
    Target.AddComment
    Target.Comment.Visible = True
    Target.Comment.Text Text:=""
    Target.Comment.Text Text:=Format(Now, "dd/mm/yy hh:mm")
On Error GoTo 0
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    tCell.Comment.Visible = False
    On Error GoTo 0
End Sub
 
Upvote 0
Keyboard shortcut for adding the date is Ctrl+; to add time use Shift + Ctrl + ;
Thank you Trevor G, however I need the date and time to appear automatic in a comment every time someone adds a comment.
 
Upvote 0
Goes in SHEET code (not a module)
Double click in cell to add the comment
click in any other cell to make it non-visible

VBA Code:
Option Explicit
Private tCell As Range
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
On Error Resume Next
    Set tCell = Target
    Target.AddComment
    Target.Comment.Visible = True
    Target.Comment.Text Text:=""
    Target.Comment.Text Text:=Format(Now, "dd/mm/yy hh:mm")
On Error GoTo 0
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    tCell.Comment.Visible = False
    On Error GoTo 0
End Sub


Thank you Yongle it works perfect
 
Upvote 0
Thank you Yongle it works perfect


Thank you Yongle it works perfect however if I want to add more information in the comment at a later date, I want a new date and time to automatically appear above the previous comment.
example below.

1597272142893.png
 
Upvote 0
VBA Code:
Option Explicit
Private tCell As Range
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
On Error Resume Next
    Dim cTxt As String, dTxt As String
    Set tCell = Target
    dTxt = Format(Now, "dd/mm/yy hh:mm") & Chr(10) & Chr(10)
    cTxt = Target.Comment.Text
    cTxt = dTxt & cTxt
    Target.AddComment
    Target.Comment.Visible = True
    Target.Comment.Text Text:=cTxt
On Error GoTo 0
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    tCell.Comment.Visible = False
    On Error GoTo 0
End Sub
 
Upvote 0
VBA Code:
Option Explicit
Private tCell As Range
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
On Error Resume Next
    Dim cTxt As String, dTxt As String
    Set tCell = Target
    dTxt = Format(Now, "dd/mm/yy hh:mm") & Chr(10) & Chr(10)
    cTxt = Target.Comment.Text
    cTxt = dTxt & cTxt
    Target.AddComment
    Target.Comment.Visible = True
    Target.Comment.Text Text:=cTxt
On Error GoTo 0
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    tCell.Comment.Visible = False
    On Error GoTo 0
End Sub


Thank you so much - it works perfectly. your amazing. :)
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,580
Members
449,089
Latest member
Motoracer88

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