We help IT Professionals succeed at work.
Get Started

Use VB Script to systematically add information to a cell comment

jmcclosk
jmcclosk asked
on
181 Views
Last Modified: 2014-09-10
I have a spreadsheet that is systematically updating cells from another source.  The cell contents gets populated with an Item#.  However, there is a lot of other information that needs to be associated with the cell, so I add all the rest of the info on to the cell comment.  It works great as long as there is only one entry per cell.

However, it is possible for the macro to comes across the cell a second time. And, I need it to append the new information to the original information that was already stored in the cell comment.  Is it possible to write something like:

Comnt = "Item Info: " & Chr(10) & Chr(13) & _
        "SKU: " & SKU2 & Chr(10) & Chr(13) & _
        "Lot#: " & Lot2 & Chr(10) & Chr(13) & _
        "Qty: " & Qty2 & Chr(10) & Chr(13) & _
        "LPN: " & LPN2 & Chr(10) & Chr(13) & Chr(10) & Chr(13) & objComment

Open in new window


the second time around?  Below is the code used to populate the cell the first time around.  Thanks!

Sheets("INVENTORY").Cells(y, x).Interior.Color = vbBlue
Sheets("INVENTORY").Cells(y, x).Value = SKU2

Comnt = "Item Info: " & Chr(10) & Chr(13) & _
        "SKU: " & SKU2 & Chr(10) & Chr(13) & _
        "Lot#: " & Lot2 & Chr(10) & Chr(13) & _
        "Qty: " & Qty2 & Chr(10) & Chr(13) & _
        "LPN: " & LPN2 & Chr(10) & Chr(13) & Chr(10) & Chr(13) & _
        "Location Info: " & Chr(10) & Chr(13) & _
        "Loc#: " & LocNum2 & Chr(10) & Chr(13) & _
        "AREA: " & s_AREA & Chr(10) & Chr(13) & _
        "WAREA: " & s_WAREA & Chr(10) & Chr(13) & _
        "WZONE: " & s_WZONE & Chr(10) & Chr(13) & _
        "Capacity: " & s_CAPACITY & Chr(10) & Chr(13) & _
        "Velocity: " & s_VELOCITY & Chr(10) & Chr(13) & _
        "Trav Seq: " & s_TRAVSEQ
        
ComLen4 = Len("Item Info: " & Chr(10) & Chr(13) & _
             "SKU: " & SKU2 & Chr(10) & Chr(13) & _
             "Lot#: " & Lot2 & Chr(10) & Chr(13) & _
             "Qty: " & Qty2 & Chr(10) & Chr(13) & _
             "LPN: " & LPN2 & Chr(10) & Chr(13) & Chr(10) & Chr(13))
        
With Sheets("INVENTORY").Cells(y, x)
    Set objComment = Sheets("INVENTORY").Cells(y, x).AddComment(Comnt)
    With objComment.Shape.TextFrame
        .Characters.Font.Size = 16
        .Characters.Font.Bold = False
        .Characters(1, 11).Font.Bold = True
        .Characters(1, 11).Font.Underline = True
        .Characters(ComLen4, 15).Font.Bold = True
        .Characters(ComLen4, 15).Font.Underline = True
    End With
End With

Sheets("INVENTORY").Cells(y, x).Comment.Visible = False
Sheets("INVENTORY").Cells(y, x).Comment.Shape.TextFrame.AutoSize = True

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE