Converting Multiple Rows into One

jburns309

New Member
Joined
Feb 1, 2019
Messages
1
I need to reorganize data output as listed below:

Source export:
Column A | Column B
Patient A | Diagnosis Code 1
Patient A | Diagnosis Code 2
Patient A | Diagnosis Code 3

Ideal Output:
Column A | Column B | Column C | Column D
Patient A | Diagnosis Code 1 | Diagnosis Code 2 | Diagnosis Code 3

I'm new to VBA, so I'll need something easy to decipher.
Thank you!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

sandy666

Banned - Rules violations
Joined
Oct 24, 2015
Messages
7,497
you can try PowerQuery aka Get&Transform

PatientDiagnosePatientDiagnose.1Diagnose.2Diagnose.3
Patient A Diagnosis Code 1Patient ADiagnosis Code 1Diagnosis Code 2Diagnosis Code 3
Patient A Diagnosis Code 2
Patient A Diagnosis Code 3

Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Patient"}, {{"Count", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Diagnose", each Table.Column([Count],"Diagnose")),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Diagnose", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Extracted Values", "Diagnose", Splitter.SplitTextByDelimiter(",", QuoteStyle.Csv), {"Diagnose.1", "Diagnose.2", "Diagnose.3"})
in
    #"Split Column by Delimiter"[/SIZE]
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,184
Messages
5,857,830
Members
431,900
Latest member
Paradime0346

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
Top