Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Code to add a comment and the text from a sheet range

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

I am hung up on how to add text to the comment where that text is a variable list of names in cells Range("P2", Range("P2").End(xlDown)).

Also, the text in the comment to be a single name per line.

Thanks,
Howard
  #2   Report Post  
Posted to microsoft.public.excel.programming
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
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Code to add a comment and the text from a sheet range


Hi Claus,

Wow, much more code than I thought ever would be needed.

Both work very nice with the Sub CommentMulti() blowing it out of the water!

I'm surprised how little I was able to find searching for examples like these you posted.

Many thanks, Claus.

Howard

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Add comment with author and text code. L. Howard Excel Programming 6 April 28th 15 07:05 PM
range.comment.Text(...) [email protected] Excel Programming 3 November 6th 07 02:36 AM
code to copy a range of cells to another sheet Robb27 Excel Programming 7 April 4th 06 11:24 AM
setting comment text from VB code Brad Sumner Excel Programming 3 March 24th 06 01:15 AM
Range's comment text Mircea Pleteriu Excel Programming 0 January 20th 05 10:36 AM


All times are GMT +1. The time now is 10:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"