+ Reply to Thread
Results 1 to 2 of 2

Problem combining comments from different cells to another cell with vba

Hybrid View

  1. #1
    Registered User
    Join Date
    06-12-2014
    Posts
    1

    Problem combining comments from different cells to another cell with vba

    Hi, I have learned a lot from the great advice from this forum. I am fairly comfortable with visual basic but This one has me stumped. I need a macro to combine one cell's comments with another cell's. My spreadsheet accumulates data and time stamped, progressive comments are necessary. I have no trouble combining two cell's comments if both cells have comments(i.e activecell.comments.text text:=range("A1").comment.text & Chr(10) & range("B1").comment.text etc..). The wrinkle I am running into is if one of the cells has no comment my macro "bugs" out. If this could be done by excel formula I would not have to post this thread. Instead of giving you an example of my macro here is basically what I need.

    I need to combine the comments from A1 and B1 into C1. If A1 has no comment I need the code to bypass that and just add the comment from B1(and vice versa if A1 has a comment and B1 does not). I have tried if conditions and else commands but I must be mucking it up somewhere. I have spent a lot of time searching online and through these forums to help myself and not bother you fine people. Any help in the right direction would be most appreciated.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Problem combining comments from different cells to another cell with vba

    Try something like this...

    Sub Combine_Comments()
        Dim cell As Range, cmt As Comment
        For Each cell In Range("A1:C1")
            If HasComment(cell) Then
                If cmt Is Nothing Then
                    Set cmt = cell.Comment
                Else
                    cmt.Text Text:=cmt.Text & vbLf & cell.Comment.Text
                End If
            End If
        Next cell
    End Sub
        
    Function HasComment(ByRef rng As Excel.Range) As Boolean
        Dim cmt As Excel.Comment
        On Error Resume Next
        Set cmt = rng.Comment
        HasComment = Not cmt Is Nothing
    End Function
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. copy cell text to comments in excel 2010 and vise versa (i.e. from comments to cell)
    By senthile in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-25-2014, 12:16 PM
  2. VBA Protection Problem w Grouping and Cell comments
    By fmaa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-22-2013, 11:03 AM
  3. Combining comments
    By Gcam85 in forum Excel General
    Replies: 2
    Last Post: 04-25-2013, 10:09 AM
  4. [SOLVED] Problem with combining cells
    By yhm in forum Excel General
    Replies: 1
    Last Post: 06-02-2005, 08:05 AM
  5. [SOLVED] Cell comments and Terminal font: BIG problem
    By Tesd in forum Excel General
    Replies: 2
    Last Post: 04-13-2005, 05:06 PM

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