Entering Different Cell Values into one Cell

carabale

Board Regular
Joined
Apr 29, 2004
Messages
133
I have a worksheet with different names. Each name might have 1 to 5 rows with comments. I want all the comments on the first line. For example:

SSN NAME COMMENT COMMENTATOR
001 PERSON1 COMMENT1 JUDGE1
001 PERSON1 COMMENT2 JUDGE2
002 PERSON2 COMMENT1 JUDGE1
003 PERSON3 COMMENT1 JUDGE1
003 PERSON3 COMMENT2 JUDGE2
003 PERSON3 COMMENT3 JUDGE3
003 PERSON3 COMMENT4 JUDGE4

I want this:

SSN NAME COMMENT
001 PERSON1 COMMENT1, COMMENT2
002 PERSON2 COMMENT1
003 PERSON3 COMMENT1, COMMENT2, COMMENT3, COMMENT4

I figure a VB will do it. Once I get the worksheet the way I need it, I will mail merge to Word. However, I can figure that part myself.

Thank you in advance for your assistance.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Can you not just use a Pivot Table? Make sure it's shown as tabular, don't repeat item labels / remove sub totals & grand totals etc...
 
Upvote 0
Assuming the data is sorted by Name and that you want the original data overwritten (so test in a copy of your workbook), try this.

Code:
Sub CombineComments()
  Dim a As Variant, b As Variant
  Dim i As Long, k As Long
  
  With Range("A1", Range("C" & Rows.Count).End(xlUp))
    a = .Value
    ReDim b(1 To UBound(a, 1), 1 To UBound(a, 2))
    For i = 2 To UBound(a)
      If a(i, 1) = a(i - 1, 1) Then
        b(k, 3) = b(k, 3) & ", " & a(i, 3)
      Else
        k = k + 1
        b(k, 1) = a(i, 1): b(k, 2) = a(i, 2): b(k, 3) = a(i, 3)
      End If
    Next i
    .Offset(1).Value = b
    .Columns(4).ClearContents
    .Columns.AutoFit
  End With
End Sub

Before:

Book1
ABCD
1SSNNAMECOMMENTCOMMENTATOR
21PERSON1COMMENT1JUDGE1
31PERSON1COMMENT2JUDGE2
42PERSON2COMMENT1JUDGE1
53PERSON3COMMENT1JUDGE1
63PERSON3COMMENT2JUDGE2
73PERSON3COMMENT3JUDGE3
83PERSON3COMMENT4JUDGE4
Combine comments



After:

Book1
ABCD
1SSNNAMECOMMENT
21PERSON1COMMENT1, COMMENT2
32PERSON2COMMENT1
43PERSON3COMMENT1, COMMENT2, COMMENT3, COMMENT4
5
Combine comments
 
Upvote 0
edit: whoops, not noticed last post. ANyway as the approach (while similar) is a bit different, I'm leaving it here.


So if you opt for VBA try:
Code:
Sub test()
Dim dataarray, i As Long, lastrow As Long
Columns("d:d").ClearContents 'not needed info about commentators
lastrow = Cells(Rows.Count, 1).End(xlUp).Row
dataarray = Range("A1:C" & lastrow).Value
For i = 2 To UBound(dataarray)
  If dataarray(i, 1) = dataarray(i - 1, 1) Then
    dataarray(i, 3) = dataarray(i - 1, 3) & ", " & dataarray(i, 3)
    dataarray(i - 1, 3) = ""
  End If
Next i
Range("A1:C" & lastrow) = dataarray
Range("A1:C" & lastrow).AutoFilter field:=3, Criteria1:=""
Rows("2:" & lastrow + 1).Delete shift:=xlUp
ActiveSheet.AutoFilterMode = False
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,565
Members
449,038
Latest member
Guest1337

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