Consulting

Results 1 to 4 of 4

Thread: Excel VBA to count the ADDITIONAL comments added to a cell

  1. #1
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    Excel VBA to count the ADDITIONAL comments added to a cell

    I am currently adding additional comments to a cell.

    Is it possible to count the additional comments added to the cell ?
    i.e : How many different comments are added, and show that running value in the comments themselves.
    So the first comment =1 , & the next comment is Comment 2 etc... etc...

    This is part of my current comments code which adds additional comments if there is a cell change;

    
    
       With Target.Offset(0, 1)
                    Set x = .Comment
                        If x Is Nothing Then
                                 .AddComment.Text Text:=Chr(10) & "$" & Target.Value & Chr(10) & "  " & strDate & ":" & " -  "  & " === " & vbCrLf
                           Else
                                 .Comment.Text .Comment.Text & vbLf & "$" & Target.Value & Chr(10) & "  " & strDate & ":" & " -  "  & " === " & vbCrLf
                         End If   
        End With
     

  2. #2
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location

    Excel VBA to count the ADDITIONAL comments added to a cell

    [QUOTE=simora;356074]I am currently adding additional comments to a cell.

    As a workaround, what I did was to store the cell changes in another column and add that cell value to the comments in the Else portion of the code like:

    Target.Offset(, 2).Value = Target.Offset(, 2).Value + 1
    newCount = Target.Offset(0, 2).Value
    Then I referenced & newCount in the Comments.
    Not the most eloquent solution, but it works for me.

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try replacing:
    If x Is Nothing Then
      .AddComment.Text Text:=Chr(10) & "$" & Target.Value & Chr(10) & "  " & strDate & ":" & " -  " & " === " & vbCrLf
    Else
      .Comment.Text .Comment.Text & vbLf & "$" & Target.Value & Chr(10) & "  " & strDate & ":" & " -  " & " === " & vbCrLf
    End If
    with:
    If x Is Nothing Then
      .AddComment.Text Text:=Chr(10) & "1. $" & Target.Value & Chr(10) & "  " & strDate & ":" & " -  " & " === " & vbCrLf
    Else
      .Comment.Text .Comment.Text & vbLf & UBound(Split(.Comment.Text, vbCrLf)) + 1 & ". $" & Target.Value & Chr(10) & "  " & strDate & ":" & " -  " & " === " & vbCrLf
    End If
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    VBAX Mentor
    Joined
    Jan 2008
    Posts
    384
    Location
    Thanks p45cal :

    That numbers each entry in the Comments. Great.

Posting Permissions

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