excelvbacommentspaste

Copy Paste to a cell Comment


Is there a way to copy paste into a cell comment? Can only do it from the clipboard, not from a cell or range reference. Or is there perhaps a vba way to call up the info in the clipboard and then paste?

Sub fillcomment()
    
    Sheets("Calendar").Select
    Application.Goto Reference:=Range(Range("Calendar!calendarRef").value)
    Application.CutCopyMode = False
    
    Sheets("FORMULAS").Select  'Surname
     Range("C8").Select
    Selection.Copy
    
    Sheets("Calendar").Select  'paste surname
    ActiveCell.Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
      Application.CutCopyMode = False
   
  
    'select and paste comment
        Sheets("Calendar").Select
        ActiveCell.ClearComments
        ActiveCell.AddComment
        ActiveCell.Comment.Visible = False
        ActiveCell.Comment.Text Text:=Range(Range("FORMULAS!calcom").value)

End Sub

I need the variable info from range named "calcom", or if easier from concatenated cells in B6 and copy paste into comment


Solution

  • Improve Macro-Recorder Code

    Sub PopulateCalendarRef()
        
        Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
        
        Dim cws As Worksheet: Set cws = wb.Sheets("Calendar")
        Dim fws As Worksheet: Set fws = wb.Sheets("Formulas")
        
        With cws.Range("calendarRef")
            .Value = fws.Range("C8").Value ' surname
            .ClearComments
            .AddComment
            '.Comment.Visible = False ' is default
            .Comment.Text CStr(fws.Range("calcom").Value)
        End With
    
    End Sub