View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default how to add text to a comment in VBA

Maybe something like:

Option Explicit
Sub testme()

Dim CmtWks As Worksheet
Dim wks As Worksheet
Dim testRng As Range
Dim myCell As Range
Dim myRng As Range

Set CmtWks = Worksheets("sheet2")
Set wks = Worksheets("sheet1")

With CmtWks
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

For Each myCell In myRng.Cells
Set testRng = Nothing
On Error Resume Next
Set testRng = wks.Range(myCell.Value).Cells(1) 'just one cell!
On Error GoTo 0

If testRng Is Nothing Then
myCell.Offset(0, 2).Value = "Invalid Range!"
Else
myCell.Offset(0, 2).ClearContents

If testRng.Comment Is Nothing Then
testRng.AddComment Text:=myCell.Offset(0, 1).Value
Else
testRng.Comment.Text _
Text:=testRng.Comment.Text _
& vbLf & myCell.Offset(0, 1).Value
End If
End If
Next myCell

End Sub

I do use column C for results. You can either delete that portion of the code
or make sure there's nothing in column C.



DB wrote:

I have a two column table on sheet2. The first column contains cell
addresses and the second are text notes. I want to loop through the cell
address and locate that address on sheet1 and place the text in a comment. I
can do this, but there are cell address that are the same. I want the text
for each to be on a new line in the same comment object.

Can anyone help with this?


--

Dave Peterson