Inserting more than one comment in a cell

edge37

Board Regular
Joined
Sep 1, 2016
Messages
69
Office Version
  1. 2021
Platform
  1. Windows
Hello! I was wondering if there is a way to insert a comment in a cell where there is already a comment. The idea is that, when you click the 2nd comment (using a macro), it gets visible in a new line at the bottom in the comment already inserted. Not cancelling one for another, but to add a new comment in the same comment dialog box.

I am using a button with this macro code already to insert a certain comment:
VBA Code:
Sub Información()
  Dim c As Range
 
  For Each c In Selection
    'If the cell already has a comment'
    On Error Resume Next: c.AddComment: On Error GoTo 0
    c.Comment.Visible = False
    
    'text in comment
    c.Comment.Text Text:="Work requires more information"
    
    'font style
    With c.Comment.Shape.TextFrame.Characters.Font
      .Size = 12
      .Name = "Arial"
      .Bold = False
    End With
    
    'Adjust the size of the comment box
    c.Comment.Shape.TextFrame.AutoSize = True
    
    'comment box property
    c.Comment.Shape.Placement = xlMoveAndSize
  Next
End Sub

Using Excel 2021. Can this be done?

Thank you
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You cannot add a Comment to a cell that already has a Comment, but you can add Text to the Comment that's already there.
Add this code to the Sheet code module of the Sheet that you want to affect.
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim cell As Range, com, newCom As String, un As String
un = Application.UserName
For Each cell In Target
    Set com = cell.Comment
    If Not com Is Nothing Then
       newCom = InputBox("This Cell has a Comment." & vbNewLine & _
        "Would you like to add to it?", "Add to Comment")
        If Not newCom = "" Then
            cell.Comment.Text vbNewLine & un & ":" & vbNewLine & newCom, Len(cell.Comment.Text) + 1, False
        End If
    End If
Next cell
End Sub
 
Upvote 0
Solution
I went a bit different path than @Skyybot
Reused original code, but instead of Error handling when comment is already there, I checked if comment object is nothing,
if it is: add new as it was done before,
if not: read old text and add dont add comment (it already is there, just change text concatenating old and new texts.

VBA Code:
Sub Información()
  Dim c As Range, old_comment As String
 
  For Each c In Selection
    If c.Comment Is Nothing Then
      old_comment = ""
      c.AddComment
    Else
        old_comment = c.Comment.Text & vbLf 'read old comment and add New_Line
    End If
    c.Comment.Visible = False
   
    'text in comment
    c.Comment.Text Text:=old_comment & "Work requires more information"
   
    'font style
    With c.Comment.Shape.TextFrame.Characters.Font
      .Size = 12
      .Name = "Arial"
      .Bold = False
    End With
   
    'Adjust the size of the comment box
    c.Comment.Shape.TextFrame.AutoSize = True
   
    'comment box property
    c.Comment.Shape.Placement = xlMoveAndSize
  Next
End Sub
 
Upvote 0
Actually, FYI, a cell can have a comment and a data validation input message at the same time making it look as if the cell has two separate comments.
 
Upvote 0

Forum statistics

Threads
1,222,903
Messages
6,168,939
Members
452,227
Latest member
sam1121

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