Combining Data Based on Previous Column Data

madhuchelliah

Board Regular
Joined
Nov 22, 2017
Messages
226
Office Version
  1. 2019
Platform
  1. Windows
Hello Folks, Greetings for the day. I have repeated data in the A column. But the equivalent values in the C column is different. I want to combine all the data into single cell in the D column if the data is not repeated in A column then the same data should be retained from C column to D column. While combining the data should be separated by comma and a space (, ). Data in the D column is the expected result. Please go through the example below for more clarity. Thank you.
[TABLE="class: grid, width: 200, align: center"]
<tbody>[TR]
[TD]A
[/TD]
[TD]B
[/TD]
[TD]C
[/TD]
[TD]D
[/TD]
[/TR]
[TR]
[TD]1A
[/TD]
[TD][/TD]
[TD]XXXXX, YYYYY
[/TD]
[TD]XXXXX, YYYYY, ZZZZ
[/TD]
[/TR]
[TR]
[TD]1A
[/TD]
[TD][/TD]
[TD]ZZZZZ
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]1B
[/TD]
[TD][/TD]
[TD]AAAAA
[/TD]
[TD]AAAAA
[/TD]
[/TR]
[TR]
[TD]1C
[/TD]
[TD][/TD]
[TD]BBBBB
[/TD]
[TD]BBBBB
[/TD]
[/TR]
[TR]
[TD]5A
[/TD]
[TD][/TD]
[TD]CCCCC
[/TD]
[TD]CCCCC, DDDDD
[/TD]
[/TR]
[TR]
[TD]5A
[/TD]
[TD][/TD]
[TD]DDDDD
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10
[/TD]
[TD][/TD]
[TD]EEEEE
[/TD]
[TD]EEEEE, FFFFF, GGGGG, HHHHH
[/TD]
[/TR]
[TR]
[TD]10
[/TD]
[TD][/TD]
[TD]FFFFF
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10
[/TD]
[TD][/TD]
[TD]GGGGG
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10
[/TD]
[TD][/TD]
[TD]HHHHH
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]15A
[/TD]
[TD][/TD]
[TD]IIIII
[/TD]
[TD]IIIII
[/TD]
[/TR]
[TR]
[TD]15B
[/TD]
[TD][/TD]
[TD]JJJJJ
[/TD]
[TD]JJJJJ
[/TD]
[/TR]
[TR]
[TD]20
[/TD]
[TD][/TD]
[TD]KKKK, LLLLL
[/TD]
[TD]KKKKK, LLLLL, MMMMM
[/TD]
[/TR]
[TR]
[TD]20
[/TD]
[TD][/TD]
[TD]MMMM
[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
How about
Code:
Sub madhuchelliah()
   Dim cl As Range
   
   With CreateObject("scripting.dictionary")
      For Each cl In Range("A2", Range("A" & Rows.Count).End(xlUp))
         If Not .exists(cl.Value) Then
            .Add cl.Value, cl
            cl.Offset(, 3).Value = cl.Offset(, 2).Value
         Else
            .item(cl.Value).Offset(, 3) = .item(cl.Value).Offset(, 3) & ", " & cl.Offset(, 2).Value
         End If
      Next cl
   End With
End Sub
 
Upvote 0
Solution
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
Latest member
laura12345

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