+ Reply to Thread
Results 1 to 4 of 4

Adding comments to cells

  1. #1
    Registered User
    Join Date
    03-26-2008
    Posts
    24

    Adding comments to cells

    I have a sheet that contains multiple tables. In the header of each table in column D are the letters Sa. I search until I find those letters. I then store that row number in StRow. I then loop through until I find a blank cell in column D. This row number is stored in rowloop. I put the value of cell(rowloop, "B") into Comtxt. What I want to do is add the text in Comtxt to each cell in column D from Strow to rowloop-1. Right now I am getting a Compiler error at the .Add Comment line of invalid or unqualified reference. This is where my object oriented programming is lacking. What is the piece I need to add the comment?

    Please Login or Register  to view this content.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Bope,

    The period prefix indicates the property or method is belongs to a With ... With End statement. You could use With in the loop like this...
    Please Login or Register  to view this content.
    Another problem you can encounter is trying to Add a comment to cell that already has a comment. You should check before doing so. If the comment exists then change the Comment's text to the new text. I modified your code to this.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    03-26-2008
    Posts
    24
    Leith,
    Thanks for the help and the VBA lesson. I did have to make a couple other tweaks. I have highlighted those in Red. The one thing I struggled with was the If statement to determine if a comment existed. What I finally had to do was delete the old Comment and add a new one. If you have a more elegant suggestion I would love to see it.

    Thanks,
    Eric

    Please Login or Register  to view this content.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Bope,

    Your solution is easy and direct. You could also clear the old comment's text by assigning it an empty string and then assign the new text. Either way is fine.

    Sincerely,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1