Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Usage a cell's content to add comment for a different cell

So my problem here is the following:
I would like to use a cell’s value which comes from a formula.
I’ll try to explain the best way:

A1’s value: x (here I need a comment)
B1’s value: yz (the text here comes from a vlookup formula)

I would like to have B1’s value in A1 cell as a comment.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is what I have, if you have a suggestion please let me know.
Thank you in advance!

Sub commenter()

Dim text As String
text = Worksheets(1).Range("B1").Value

Worksheets(1).Range("A1").AddComment text

End Sub

>Solution :

The code you have should work – however only if the cell doesn’t have a comment. If it has already a comment, you will get a runtime error 1004.

As the text-property of a comment is read-only, you cannot modify the text, so best is to simply delete it before you set it:

With ThisWorkbook.Sheets(1)
    Dim text As String, cell As Range
    text = .Range("B1").Value
    Set cell = .Range("A1")
    If Not cell.Comment Is Nothing Then cell.Comment.Delete
    cell.AddComment text
End With
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading