VBA to bring columns in rows (except first column)

Dampa88

Board Regular
Joined
Apr 28, 2016
Messages
53
Office Version
  1. 365
Platform
  1. Windows
Dear all,

I'm struggling with a code to move columns values into rows, except the first column.
Of course, it will be needed to add rows and populate the blanks in the first column.

Probably, an example will make my exercise easier to understand:

Example.png



An important point is that the number of columns may change.

I have been able to add a certain number of rows after the first one and transpose the values.
Then I'm blocked when I need to move to the next value of the first columns.

I know that there is a easier code, I hope you can give me some inputs.

Thanks,
D
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
This is a simple unpivot using Power Query.

Here is the Mcode for that procedure. Look at the links in my signature for more information on this Excel function.

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Unique", type text}, {"InfoA", type text}, {"InfoB", type text}, {"InfoC", type text}, {"InfoD", type text}, {"InfoE", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Unique"}, "Attribute", "Value")
in
    #"Unpivoted Other Columns"

Data Range
A
B
C
2
A​
InfoA​
Home​
3
A​
InfoB​
North​
4
A​
InfoC​
West​
5
A​
InfoD​
Sunny​
6
A​
InfoE​
Hot​
7
B​
InfoA​
Office​
8
B​
InfoB​
Sud​
9
B​
InfoC​
East​
10
B​
InfoD​
Cloudy​
11
B​
InfoE​
Cold​
 
Upvote 0
Thanks for the very fast reply and for the hint!
I'd never think about unpivot.

KR,
D
 
Upvote 0

Forum statistics

Threads
1,214,857
Messages
6,121,948
Members
449,056
Latest member
FreeCricketId

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