How to concatenate values in column with same primary key?

burghman217

New Member
Joined
Jan 30, 2017
Messages
10
Essentially, I have a worksheet that looks like this:

Record IDCandidate IDFirst NameLast NameFirstNameLastNameSkill Record IDSkill Name
70640961204825Jamie BurkholderJamie Burkholder550001252Operations
70640971204825Jamie BurkholderJamie Burkholder550002280Purchasing
70640981204825Jamie BurkholderJamie Burkholder550001513Bartender
70640991204825Jamie BurkholderJamie Burkholder550001254Sales
71599471213663Stacey MccorkleStacey Mccorkle550002187Pharmacist
71599481213663Stacey MccorkleStacey Mccorkle550001651Compliance
71599491213663Stacey MccorkleStacey Mccorkle550001746Dispensing
71599501213663Stacey MccorkleStacey Mccorkle550001957Inventory
71599511213663Stacey MccorkleStacey Mccorkle550001254Sales
71599521213663Stacey MccorkleStacey Mccorkle550001218Writing
71599531213663Stacey MccorkleStacey Mccorkle550001662Consultant

<tbody>
</tbody>

but I need to get it into the following format:

Record IDCandidate IDFirst NameLast NameFirstNameLastNameSkills
70640961204825Jamie BurkholderJamie BurkholderOperations, Purchasing, Bartender, Sales
71599471213663Stacey MccorkleStacey MccorklePharmacist, Compliance, Dispensing, Inventory, Sales, Writing, Consultant

<tbody>
</tbody>

The data is unfortunately hundreds of thousands of rows long, so it's not efficient to apply the TEXTJOIN function manually. Any ideas?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Welcome to the Board!

Give this VBA code a try:
Code:
Sub CombineRecords()

    Dim myRow As Long
    
'   Enter which row data starts on (excluding header)
    myRow = 2
    
    Application.ScreenUpdating = False
    
'   Loop until out of data
    Do Until Cells(myRow, "A") = ""
'       Check to see if next row is for same person (using Candidate ID - column B)
        If Cells(myRow, "B") = Cells(myRow + 1, "B") Then
'           Add Skill name to end (column G)
            Cells(myRow, "G") = Cells(myRow, "G") & ", " & Cells(myRow + 1, "G")
'           Then delete row
            Rows(myRow + 1).Delete
        Else
'           Move down one row if no match
            myRow = myRow + 1
        End If
    Loop
            
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
You are welcome!
 
Upvote 0
I'm hoping you can actually help me with two more, similar scenarios (please let me know if I should be posting this to
a separate thread!).


Basically, I need the data from each row to roll up into separate, repeating columns based upon the primary key, Candidate ID (see images in link below). Is this possible?


Education & Work History - Album on Imgur
 
Upvote 0
I cannot see your image. Workplace security blocks those sites for me.

Basically, the rule of thumb is this:
- If it is a directly-related follow-up on the original question (where the answer to the original question is pertinent), then paste it in the same thread.
- If it is a brand new question that is not dependent upon the previous question/response, post it in a new thread.
 
Upvote 0
I solved it with a formula (I use O365, hence used TextJoin & XLOOKUP: you can use CONCAT & VLOOKUP if you are on older versions that do not support these functions: below is what the formula in Row 6 looks like

If you are expecting more than 3 records per data: This will give complete CONCAT in the 1st row of the concerned primary Key
=TEXTJOIN("; ",TRUE,[@[Skill Name]],XLOOKUP([@[Candidate ID]],B7:$B$13,I7:$I$13,""))
Basically, VLOOKUP Concatenated values of the target column from in rows below, and concat them all into a single row



If you are expecting upto 3 records per data: this will give complete concat in all records (EG. my data in the sheet
=TEXTJOIN(";",TRUE,[@[Skill Name]],XLOOKUP([@[Candidate ID]],$B$1:B5,$G$1:G5,""),XLOOKUP([@[Candidate ID]],B7:$B$15,G7:$G$15,""))

Basically, VLOOKUP values from the target column in rows above and rows below, and concat them all into a single row

Unable to upload pictures: Keep getting the message "Uploaded file is too large" for even a 500KB pic
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,375
Members
449,155
Latest member
ravioli44

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