Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I'm trying to write a macro for a workbook where the text of a cell in one sheet receives formulated information from another sheet in the form of a comment. Say cell E5, sheet1 has the text "data"- that text cooresponds to the text "data" on sheet2, though not nexessarily in the same order. What I need to do is take a concatenated formula to the right of the sheet2 data, copy the text, and insert it into a comment of the original E5, sheet1.
However, I can't seem to find a way for the exec to reference the text in one sheet to pull data from the other. I've tried the find action, using variables, etc, but I can't seem to get it right. Any ideas?

I don't know what you mean when you say "the text of a cell in one sheet receives formulated information from another sheet in the form of a comment."
What does "formulated information" mean?
Are you talking about actual Excel comments as in Insert...Comment?
Please provide an example of the input text and the output text and any other details that you think might help us provide some suggestions.

Absolutely-
Yes, I do mean the insert-comment form, sorry for the confusion. The "formulated information" was just the conatanate of other cells- but I changed it, so now it's just text. What I need to do is start with a cell's text, find that text in another sheet, and copy data from the right of it into an insert-comment field on the original cell.
I don't know if the file would help at all (I can certainly upload it)- most of it is irrelevant to the task at hand, however. Thanks for the response.

Let's say you have this set-up:
Sheet1A B
1 He Drives A Car
2 His Name Is Fred
3 She Has A House
Sheet2A..B..C..D E
1
...
14
15 His NameThis code will look for the text in Sheet2!E15 (His Name) in Sheet1!A1:A3 and insert a comment in Sheet2!E15 containing the text in Sheet1!B2 (Fred) since His Name was found in Sheet1!A2.
Note: If there is already a Comment attached to E15, the code will fail. You have to delete an existing comment before you can add one.
Sub CommentBuilder()
With Worksheets(1).Range("A1:A3")
'Find the text from Sheet2!E15 in Sheet1!A1:A3
Set c = .Find(Worksheets(2).Range("E15"), LookIn:=xlValues, lookat:=xlPart)
'If found, place the text from Sheet1!B(whatever) in a comment in Sheet2!E15
If Not c Is Nothing Then
Worksheets(2).Range("E15").AddComment c.Offset(0, 1).Value
End If
End With
End Sub

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |