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.
A
B
C
D
1A
XXXXX, YYYYY
XXXXX, YYYYY, ZZZZ
1A
ZZZZZ
1B
AAAAA
AAAAA
1C
BBBBB
BBBBB
5A
CCCCC
CCCCC, DDDDD
5A
DDDDD
10
EEEEE
EEEEE, FFFFF, GGGGG, HHHHH
10
FFFFF
10
GGGGG
10
HHHHH
15A
IIIII
IIIII
15B
JJJJJ
JJJJJ
20
KKKK, LLLLL
KKKKK, LLLLL, MMMMM
20
MMMM

<tbody>
</tbody>
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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,214,987
Messages
6,122,614
Members
449,090
Latest member
vivek chauhan

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