Merge cell contents based on a shared value

craigs85

New Member
Joined
Jan 14, 2017
Messages
26
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I am trying to do something reasonably complicated in excel, and not sure what way I should do it.

I basically have a list of car parts but there are a lot of part numbers that apply to multiple vehicles.

I have a Make, Model, Submodel, Product Code Column (plus lots more - but these 4 are the main ones of concern.

An example will be:

Make,Model,Submodal,Product Code
Ford,Focus,Mk1,000001
Ford,Focus,MK2,000001
Ford,Focus,MK3,000001
Audi,A1,1.2,000001
Audi,A4,1.4,000001

And so on.

What I would like, is to merge all of the makes, models, and submodals so they appear pipe seperated in a single cell (for each), where they have the same product code).

So the example above would look like.

Make,Model,Submodal,Product Code
Ford|Audi,Focus|A1|A4,Mk1|MK2|MK3|1.2|1.4,000001

Does that make sense?

Can anyone suggest what I can do please?

Thanks so much in advance!

Craig
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi,

Can you try this (formula is sort of big but will work if you have O365):

Book1
ABC
1Make,Model,Submodal,Product CodeMake,Model,Submodal,Product CodeMake,Model,Submodal,Product Code
2Ford,Focus,Mk1,000001000001Ford,Audi|Focus,A1|Mk1,MK2,MK3,1.2|000001
3Ford,Focus,MK2,000001000002Audi|A4|1.4|000002
4Ford,Focus,MK3,000001
5Audi,A1,1.2,000001
6Audi,A4,1.4,000002
Sheet1
Cell Formulas
RangeFormula
B2:B3B2=UNIQUE(TRIM(RIGHT(SUBSTITUTE(A2:A6,",",REPT(" ",LEN(A2:A6))),LEN(A2:A6))))
C2:C3C2=TEXTJOIN("|",TRUE,TEXTJOIN(",",TRUE,UNIQUE(TRIM(MID(SUBSTITUTE(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6)))),",",REPT(" ",LEN(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6))))))),(1-1)*LEN(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6)))))+1,LEN(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6))))))))),TEXTJOIN(",",TRUE,UNIQUE(TRIM(MID(SUBSTITUTE(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6)))),",",REPT(" ",LEN(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6))))))),(2-1)*LEN(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6)))))+1,LEN(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6))))))))),TEXTJOIN(",",TRUE,UNIQUE(TRIM(MID(SUBSTITUTE(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6)))),",",REPT(" ",LEN(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6))))))),(3-1)*LEN(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6)))))+1,LEN(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6))))))))),TEXTJOIN(",",TRUE,UNIQUE(TRIM(MID(SUBSTITUTE(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6)))),",",REPT(" ",LEN(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6))))))),(4-1)*LEN(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6)))))+1,LEN(FILTER($A$2:$A$6,B2=TRIM(RIGHT(SUBSTITUTE($A$2:$A$6,",",REPT(" ",LEN($A$2:$A$6))),LEN($A$2:$A$6))))))))))
Dynamic array formulas.
 
Upvote 0
Thanks for much for getting back to me.
I don't think I explained very well initially.

Make,Model,Submodal,Product Code are excel columns, not all contents of a single column and cell.

I didn't know how to post if how you have done..

Column A is Make, B is Model, C is Submodal and D is Product Code.

Does that make sense?
 
Upvote 0
Hi & welcome to MrExcel.
What version of Excel are you using?
Please update your account details to show this, as it affects which functions you can use.

You can post sample data to the board like tyija1995 did by using the XL2BB add-in. See my signature for a link.
 
Upvote 0
OK now I see that they are different columns each, then try this:

Book1
ABCDEFGH
1MakeModelSubmodalProduct CodeMASTERUnique Product Codes
2FordFocusMk1000001Ford,Audi|Focus,A1|Mk1,Mk2,Mk3,1.2|000001000001
3FordFocusMk2000001Audi|A4|1.4|000002000002
4FordFocusMk3000001
5AudiA11.2000001
6AudiA41.4000002
Sheet1 (2)
Cell Formulas
RangeFormula
H2:H3H2=UNIQUE(D2:D6)
F2:F3F2=TEXTJOIN("|",TRUE,TEXTJOIN(",",TRUE,UNIQUE(FILTER(A$2:A$6,$D$2:$D$6=$H2))),TEXTJOIN(",",TRUE,UNIQUE(FILTER(B$2:B$6,$D$2:$D$6=$H2))),TEXTJOIN(",",TRUE,UNIQUE(FILTER(C$2:C$6,$D$2:$D$6=$H2))),TEXTJOIN(",",TRUE,UNIQUE(FILTER(D$2:D$6,$D$2:$D$6=$H2))))
Dynamic array formulas.


Again it requires O365 (so I am really hoping you are using that, otherwise I will not be able to help answer your question)

In this method I have generated a distinct list of product codes to help aid the formulae used
 
Upvote 0
Thanks very much, Profile updated.

Here is my sheet, using 2016 Excel.

price-list-export-29-11-2020.xlsx
ABCD
1MakeModelSubmodalProduct Code
2FordFocusMK1000001
3FordFocusMk2000001
4FordFocusMk3000001
5AudiA11.2000001
6AudiA41.4000001
Sheet2
 
Upvote 0
Profile updated.
Thanks for that.

Unfortunately what you want will be very difficult to do in your version of Excel, with functions alone.
Are you happy to have a VBA solution?
 
Upvote 0
Thanks for that.

Unfortunately what you want will be very difficult to do in your version of Excel, with functions alone.
Are you happy to have a VBA solution?
Yeah definitely ?.
I would be happy to have any solution haha.

The sheet I have has about 4000 rows like the one I provided, and with extra columns on the end like description and price etc, but these are all the same for per product code, but I would need them on my 'new' bits.

Does that make sense?
 
Upvote 0
Ok, I'm off now, but will have a look tomorrow if no-one else jumps in.
 
Upvote 0

Forum statistics

Threads
1,215,235
Messages
6,123,789
Members
449,126
Latest member
Greeshma Ravi

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