Multiple cells into comment

Toomicek

New Member
Joined
Oct 8, 2014
Messages
28
Hi there,

I want to add text from 3-5 cells in different sheets to one cell like commentary. I am not a pro in VBA so i need help :)

Added sample
Bez_n_zvu.jpg


Thanks

Thomas
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I'm not sure I can help anyway but your requirement is not clear to me and maybe that is also why others are not responding.

Your screen shot sort of makes sense but your written description doesn't match it as that referred to cells on different sheets. Please clarify.
 
Upvote 0
I'm not sure I can help anyway but your requirement is not clear to me and maybe that is also why others are not responding.

Your screen shot sort of makes sense but your written description doesn't match it as that referred to cells on different sheets. Please clarify.

Lets assume that all those input charts are on different sheets or if you can make it to work on one sheet I can adjust it for my needs :)

In short: Can you make it work like it is on screenshot?


Thank you for reply :)
 
Upvote 0
In short: Can you make it work like it is on screenshot?
Thomas, that is what I have attempted - for that exact layout but monitoring for changes in G16:G20.

Test in a copy of your workbook.

To implement ..

1. Right click the sheet name tab and choose "View Code".

2. Copy and Paste the code below into the main right hand pane that opens at step 1.

3. Close the Visual Basic window & test.

4. If using Excel 2007 or later your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range
  Dim s As String, cmt As String, sBold As String
  Dim aTLC As Variant, aData As Variant, aBold As Variant
  Dim i As Long, Tbl As Long
  Dim bStarted As Boolean
  
  Const TopLeftCells As String = "A1 D1 G1" '<- Top left cell of each table
  Const CommentCells As String = "G16:G20"  '<- Range to add/delete/edit comments
  
  Set Changed = Intersect(Target, Range(CommentCells))
  If Not Changed Is Nothing Then
    aTLC = Split(TopLeftCells)
    For Each c In Changed
      c.ClearComments
      s = c.Text
      If Len(s) > 0 Then
        For Tbl = 0 To UBound(aTLC)
          aData = Range(aTLC(Tbl)).CurrentRegion.Value
          bStarted = False
          For i = 2 To UBound(aData, 1)
            If aData(i, 1) = s Then
              If Not bStarted Then
                sBold = sBold & "," & Len(cmt) + 1 & "," & Len(aData(1, 2))
                bStarted = True
                cmt = cmt & vbLf & aData(1, 2)
              End If
              cmt = cmt & vbLf & aData(i, 2)
            End If
          Next i
        Next Tbl
        If Len(cmt) > 0 Then
          c.AddComment.Text Text:=Mid(cmt, 2)
          aBold = Split(sBold, ",")
          For i = 1 To UBound(aBold) Step 2
            c.Comment.Shape.TextFrame.Characters(aBold(i), aBold(i + 1)).Font.Bold = True
          Next i
          c.Comment.Shape.TextFrame.AutoSize = True
        End If
      End If
    Next c
  End If
End Sub
 
Upvote 0
Thomas, that is what I have attempted - for that exact layout but monitoring for changes in G16:G20.

Test in a copy of your workbook.

To implement ..

1. Right click the sheet name tab and choose "View Code".

2. Copy and Paste the code below into the main right hand pane that opens at step 1.

3. Close the Visual Basic window & test.

4. If using Excel 2007 or later your workbook will need to be saved as a macro-enabled workbook (*.xlsm)

Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim Changed As Range, c As Range
  Dim s As String, cmt As String, sBold As String
  Dim aTLC As Variant, aData As Variant, aBold As Variant
  Dim i As Long, Tbl As Long
  Dim bStarted As Boolean
  
  Const TopLeftCells As String = "A1 D1 G1" '<- Top left cell of each table
  Const CommentCells As String = "G16:G20"  '<- Range to add/delete/edit comments
  
  Set Changed = Intersect(Target, Range(CommentCells))
  If Not Changed Is Nothing Then
    aTLC = Split(TopLeftCells)
    For Each c In Changed
      c.ClearComments
      s = c.Text
      If Len(s) > 0 Then
        For Tbl = 0 To UBound(aTLC)
          aData = Range(aTLC(Tbl)).CurrentRegion.Value
          bStarted = False
          For i = 2 To UBound(aData, 1)
            If aData(i, 1) = s Then
              If Not bStarted Then
                sBold = sBold & "," & Len(cmt) + 1 & "," & Len(aData(1, 2))
                bStarted = True
                cmt = cmt & vbLf & aData(1, 2)
              End If
              cmt = cmt & vbLf & aData(i, 2)
            End If
          Next i
        Next Tbl
        If Len(cmt) > 0 Then
          c.AddComment.Text Text:=Mid(cmt, 2)
          aBold = Split(sBold, ",")
          For i = 1 To UBound(aBold) Step 2
            c.Comment.Shape.TextFrame.Characters(aBold(i), aBold(i + 1)).Font.Bold = True
          Next i
          c.Comment.Shape.TextFrame.AutoSize = True
        End If
      End If
    Next c
  End If
End Sub

That works very well THANKS!!! :)

Imagine if you can set it up for change in input charts? Like if A1:H6 changes than do new comments?
 
Upvote 0
Imagine if you can set it up for change in input charts? Like if A1:H6 changes than do new comments?
Rather than start over again, I think a quick fix would be to change the existing red line below into the blue one. Give that a try.
Rich (BB code):
Set Changed = Intersect(Target, Range(CommentCells))
Set Changed = Range(CommentCells)
 
Upvote 0
Rather than start over again, I think a quick fix would be to change the existing red line below into the blue one. Give that a try.
Rich (BB code):
Set Changed = Intersect(Target, Range(CommentCells))
Set Changed = Range(CommentCells)

This didnt work. This copies previous comment in it :( Moved it and used
Code:
Const CommentCells As String = "J4:J8"

Maybe i will use button to get comments like (REFRESH) or something so users can refresh it and see comments.

Bez_n_zvu.png
 
Upvote 0
This didnt work. This copies previous comment in it :(
1. Just confirming, from your image mainly, that what you are saying is that with the post #7 change, when you change values in the tables that the original comment stays, but has more text added to it?

2. What version of Excel are you using?

3. Can you also confirm whether the values in the tables are changed manually or are they formulas?
 
Upvote 0
1. Just confirming, from your image mainly, that what you are saying is that with the post #7 change, when you change values in the tables that the original comment stays, but has more text added to it?

2. What version of Excel are you using?

3. Can you also confirm whether the values in the tables are changed manually or are they formulas?

1. When I moddified original code with #7 edit, than when I changed anything in tables, it generates new comments with last one showing all previous data. "NOT INTEDNED" :)
2.Excel 2013
3.They are changed manualy by user
 
Upvote 0

Forum statistics

Threads
1,215,232
Messages
6,123,765
Members
449,120
Latest member
Aa2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top