View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Claus Busch Claus Busch is offline
external usenet poster
 
Posts: 3,872
Default Code to add a comment and the text from a sheet range

Hi Howard,

Am Fri, 14 Aug 2015 18:19:19 -0700 (PDT) schrieb L. Howard:

I can easily write code to add a comment to cell C1, with the comment text hard coded.


try:

Sub CommentMulti()
Dim varData() As Variant
Dim Lrow As Long, i As Long
Dim strComment As String
Dim rngC As Range

Lrow = Cells(Rows.Count, "P").End(xlUp).Row
ReDim Preserve varData(Lrow - 2)
For Each rngC In Range("P2:P" & Lrow)
varData(i) = rngC
i = i + 1
Next
strComment = Join(varData, Chr(10))

With Range("C1")
.AddComment strComment
.Comment.Shape.TextFrame.AutoSize = True
End With
End Sub

Sub CommentSingle()
Dim varData As Variant
Dim i As Long, Lrow As Long

Lrow = Cells(Rows.Count, "P").End(xlUp).Row
varData = Range("P2:P" & Lrow)

For i = LBound(varData) To UBound(varData)
Cells(i, "D").AddComment varData(i, 1)
Next
End Sub


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional