PDA

View Full Version : range of cell comments with same text, how?



Ago
11-24-2008, 04:05 AM
i have a code that creates a string, textstr, in a loop.
when the string is complete i use this code to place the string in cellcommments.



For k = 1 To j
With Range("G" & i + k - 1)
.AddComment
.Comment.Text Text:=textstr
.Comment.Shape.TextFrame.AutoSize = True
End With
Next k


it feels ridicilous to have a loop when i know which cells should have this string.
is there any way i could use something like

Range("G" & i, "G" & i+j).AddComment
Range("G" & i, "G" & i+j).Comment.Text Text:=textstr
Range("G" & i, "G" & i+j).Comment.Shape-TextFrame.Autosize = True

but it seems comments can only be added one at the time.
any suggestions?

Hoopsah
11-24-2008, 06:33 AM
I have a macro that adds a comment to all selected cells:

Sub InsertCommentsSelection()
Dim sCmt As String
Dim rCell As Range
sCmt = InputBox( _
Prompt:="Enter Comment to Add" & vbCrLf & _
"Comment will be added to all cells in Selection", _
Title:="Comment to Add")
If sCmt = "" Then
MsgBox "No comment added"
Else
For Each rCell In Selection
With rCell
.ClearComments
.AddComment
.Comment.Text Text:=sCmt
End With
Next
End If
Set rCell = Nothing
End Sub

Don't know if you could tweak this a bit.