תשובה Use of AddComment in VBA Excel 2007

  • Wednesday, July 01, 2009 9:28 PM
     
     
    When trying to insert a comment in a cell, It works OK this way:

    Range("A1").AddComment "Text"

    But when trying to insert a comment with a cell's content, It does not Work:

    Range("A1").AddComment Range("B1").value

    Is there any way to include in a cell a comment the value of another cell?

All Replies

  • Wednesday, July 01, 2009 10:01 PM
     
     Answered
    Surely:
    a = Worksheets("Sheet1").Cells(2, 1).Value
    Range("A3").AddComment (Str(a))
    • Marked As Answer by Tim LiModerator Wednesday, August 05, 2009 2:14 AM
    •  
  • Thursday, July 02, 2009 8:12 AM
     
     Answered
    You can try this way also.

    Range("a2").AddComment Range("b1").Text
    • Marked As Answer by Tim LiModerator Wednesday, August 05, 2009 2:14 AM
    •  
  • Thursday, July 02, 2009 9:22 AM
     
     Answered
    What does "It does not Work" mean exactly?

    Do you get this error.

    ---------------------------
    Microsoft Visual Basic
    ---------------------------
    Run-time error '1004':

    Application-defined or object-defined error
    ---------------------------
    OK   Help  
    ---------------------------

    If so it caused by trying to add a comment to a cell that already has a comment.

    Cheers www.andypope.info
    • Marked As Answer by Tim LiModerator Wednesday, August 05, 2009 2:14 AM
    •  
  • Monday, June 07, 2010 5:50 PM
     
     
    Hi, I'm getting this error using AddComment, I have excel 2007. Please advise what do. Thanks a lot.
  • Monday, June 07, 2010 6:47 PM
     
     

    For adding a comment:

    Range("A1").AddComment ("test")

    For changing the existing comment:

    Range("A2").Comment.Text Text:="test"

  • Tuesday, June 08, 2010 5:58 PM
     
     

    Thanks for that. now is inserting the comments

    I think i found why i'm getting this error:

    Run-time error '1004':

    Application-defined or object-defined error

    When I'm trying to addcomment when the cell has a comment.

    but when i use  rng.Addcomment.delete and rng.comment.delete to delete the comment i'm getting this error:

    run-time error 91

    object variable or with block variable not set

    Please advise how to solve this.

    this variables are defined in this way.

    Dim rng As Range

    Set rng = Worksheets("sheet1").Cells( i,j)

  • Tuesday, June 08, 2010 6:44 PM
     
      Has Code

    For deleting a comment, you may use

    Range("A1").Comment.Delete 

    or

    Cells(i,j).Comment.Delete