Need to merge cells in a single column based on value of another column

imeade

New Member
Joined
Jun 28, 2022
Messages
16
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have data in two columns A & B, I need to merge the rows in Column B into a single cell based on the value in Column A with a "-" separating them, and drop into columns C & D, please see below:

Column AColumn BColumn CColumn D
DataMacro Output
AccountNameAccountName
12345​
ABC
12345​
ABC-Jeff-CDE-Bob
12345​
Jeff
67890​
Kyle-JKL-Ruth-XYZ
12345​
CDE
12345​
Bob
67890​
Kyle
67890​
JKL
67890​
Ruth
67890​
XYZ



Thanks in advance!
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
How about
Fluff.xlsm
ABCDE
1AccountNameAccountName
212345ABC12345ABC-Jeff-CDE-Bob
312345Jeff67890Kyle-JKL-Ruth-XYZ
412345CDE
512345Bob
667890Kyle
767890JKL
867890Ruth
967890XYZ
10
Code
Cell Formulas
RangeFormula
D2:E3D2=LET(u,UNIQUE(FILTER(A2:A100,A2:A100<>"")),HSTACK(u,BYROW(u,LAMBDA(br,TEXTJOIN("-",,FILTER(B2:B100,A2:A100=br))))))
Dynamic array formulas.
 
Upvote 0
How about
Fluff.xlsm
ABCDE
1AccountNameAccountName
212345ABC12345ABC-Jeff-CDE-Bob
312345Jeff67890Kyle-JKL-Ruth-XYZ
412345CDE
512345Bob
667890Kyle
767890JKL
867890Ruth
967890XYZ
10
Code
Cell Formulas
RangeFormula
D2:E3D2=LET(u,UNIQUE(FILTER(A2:A100,A2:A100<>"")),HSTACK(u,BYROW(u,LAMBDA(br,TEXTJOIN("-",,FILTER(B2:B100,A2:A100=br))))))
Dynamic array formulas.

Thanks but that doesn't seem to work on my excel, I should have also noted I was looking for a macro, will update my post, thanks again
 
Upvote 0
Do you really need a macro?
If you don't have Hstack then another option is
Fluff.xlsm
ABCDE
1AccountNameAccountName
212345ABC12345ABC-Jeff-CDE-Bob
312345Jeff67890Kyle-JKL-Ruth-XYZ
412345CDE
512345Bob
667890Kyle
767890JKL
867890Ruth
967890XYZ
10
Code
Cell Formulas
RangeFormula
D2:D3D2=UNIQUE(FILTER(A2:A100,A2:A100<>""))
E2:E3E2=TEXTJOIN("-",,FILTER($B$2:$B$100,$A$2:$A$100=D2))
Dynamic array formulas.
 
Upvote 0
Solution
Do you really need a macro?
If you don't have Hstack then another option is
Fluff.xlsm
ABCDE
1AccountNameAccountName
212345ABC12345ABC-Jeff-CDE-Bob
312345Jeff67890Kyle-JKL-Ruth-XYZ
412345CDE
512345Bob
667890Kyle
767890JKL
867890Ruth
967890XYZ
10
Code
Cell Formulas
RangeFormula
D2:D3D2=UNIQUE(FILTER(A2:A100,A2:A100<>""))
E2:E3E2=TEXTJOIN("-",,FILTER($B$2:$B$100,$A$2:$A$100=D2))
Dynamic array formulas.
That works, thanks!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

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