Macro to take list of names make them headers and creat list of sub names in each colum

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,210
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

Below is an example of what i currently have and what i want.

So In column A I have a list of Header Names, the names repeat for every row from 2 till last row, each header can have any amount in it so one kight only have two headers, another might be 15-25 or more.
I want to take this list and for each unique Name create a column header starting at AA of same sheet.
the column b, list all the sub headers,
I'd like to take these and add them to the columns there headers are in as in example "What I want"

please help if you can

Thanks

Tony

What i want
AAABACADAEAF
1Name1Name2Name3Name4Name5
2Sub a1Sub b1Sub c1Sub d1Sub e1
3Sub a2Sub b2Sub c2Sub d2Sub e2
4Sub a3Sub c3Sub d3
5Sub d4
6
7
8
9

(What I Have)
ABC
1Header NamesSub Names
2Name1Sub a1
3Name1Sub a2
4Name1Sub a3
5Name2Sub b1
6Name2Sub b2
7Name3Sub c1
8Name3Sub c2
9Name3Sub c3
10Name4Sub d1
11Name4Sub d2
12Name4Sub d3
13Name4Sub d4
14Name5Sub e1
15Name5Sub e2
TILL END OF DATA
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Employing Power Query/Get and Transform, this task can be accomplished with the Mcode that follows. Use the Unpivot function within PQ.

VBA Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Name1", type text}, {"Name2", type text}, {"Name3", type text}, {"Name4", type text}, {"Name5", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {}, "Attribute", "Value"),
    #"Sorted Rows" = Table.Sort(#"Unpivoted Columns",{{"Attribute", Order.Ascending}})
in
    #"Sorted Rows"
 
Upvote 0

Forum statistics

Threads
1,224,845
Messages
6,181,298
Members
453,030
Latest member
PG626

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