auntie bella
Board Regular
- Joined
- Apr 3, 2009
- Messages
- 50
Hi Guys,
I have some code that does a lookup from sheet1 to sheet2 and updates the sheet1 comments from the sheet2 comments.
Is it possible to make it so that if I update a comment on sheet2 it will automatically update the comments on sheet1? Any pointers gratefully received.
Here is my code so far - I am happy for info on any flaws or errors you might notice. (I'm trying to teach myself and this took me ages! - quite embarrassed at how little there actually is!! )
Sub CommentAddOrEdit()
Dim x
Dim y
Dim Found1 As Range
Dim Found2
Dim cmt
' get contents of current cell
Set Found1 = ActiveCell
' goto next sheet
Sheets("Sheet2").Activate
' find matching cell and get the comment
Set Found2 = Sheets("Sheet2").Rows("1:1").Find(What:=Found1.Value, LookAt:=xlWhole)
Application.Goto Reference:=Found2
cmt = Found2.Comment.Text
' go back to 1st sheet
Sheets("Sheet1").Activate
'create comment based on comment found on sheet2
If ActiveCell.Comment Is Nothing Then
ActiveCell.AddComment
ActiveCell.Comment.Text cmt
Else
ActiveCell.Comment.Delete
ActiveCell.AddComment
ActiveCell.Comment.Text cmt
End If
End Sub
many thanks
I have some code that does a lookup from sheet1 to sheet2 and updates the sheet1 comments from the sheet2 comments.
Is it possible to make it so that if I update a comment on sheet2 it will automatically update the comments on sheet1? Any pointers gratefully received.
Here is my code so far - I am happy for info on any flaws or errors you might notice. (I'm trying to teach myself and this took me ages! - quite embarrassed at how little there actually is!! )
Sub CommentAddOrEdit()
Dim x
Dim y
Dim Found1 As Range
Dim Found2
Dim cmt
' get contents of current cell
Set Found1 = ActiveCell
' goto next sheet
Sheets("Sheet2").Activate
' find matching cell and get the comment
Set Found2 = Sheets("Sheet2").Rows("1:1").Find(What:=Found1.Value, LookAt:=xlWhole)
Application.Goto Reference:=Found2
cmt = Found2.Comment.Text
' go back to 1st sheet
Sheets("Sheet1").Activate
'create comment based on comment found on sheet2
If ActiveCell.Comment Is Nothing Then
ActiveCell.AddComment
ActiveCell.Comment.Text cmt
Else
ActiveCell.Comment.Delete
ActiveCell.AddComment
ActiveCell.Comment.Text cmt
End If
End Sub
many thanks