Turning data Horizontal to logical table based

exllearner

New Member
Joined
Jan 1, 2018
Messages
4
hello,

I have data like below.

Family_Name | People In the Family
ABC | 1a| 2a|3a|4a|5a
CDE | 1b|2b| 3b|
FGH | 1c|
IJK |1d| 2d| 3d|4d|

Like above I have like 15columns*5000 rows of data but I want to see it like below

ABC
1a
2a
3a
4a
5a
CDE
1b
2b
3b
FGH
1c

...etc or in the smiler format but within two different columns is also fine.
I tried with pivot but it does not look like I get much help when I have uneven columns like this. So, please give me possible solutions.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi & welcome to the board.
How about
Code:
Sub AddRowsTranspose()

   Dim Cnt As Long
   Dim Rws As Long
   
   For Cnt = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      Rws = WorksheetFunction.CountA(Rows(Cnt)) - 1
      Range("A" & Cnt + 1).Resize(Rws).EntireRow.Insert
      Range("A" & Cnt + 1).Resize(Rws).Value = Application.Transpose(Range("B" & Cnt).Resize(, Rws).Value)
   Next Cnt
   Range("B:O").Delete
End Sub
As this deletes columns make sure you try it on a copy
 
Upvote 0
Hi FLuff,

This works great but when I have huge data this does not look good and if every family name has ID association like below


ID| Family_Name | People In the Family
ID1| ABC | 1a| 2a|3a|4a|5a


i want to change to the below, c


ID| Family_Name | People In the Family
ID1| ABC | 1a
ID1| ABC | 2a
ID1| ABC | 3a
ID1| ABC | 4a
ID1| ABC | 5a


many thanks in advance.
Hi & welcome to the board.
How about
Code:
Sub AddRowsTranspose()

   Dim Cnt As Long
   Dim Rws As Long
   
   For Cnt = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      Rws = WorksheetFunction.CountA(Rows(Cnt)) - 1
      Range("A" & Cnt + 1).Resize(Rws).EntireRow.Insert
      Range("A" & Cnt + 1).Resize(Rws).Value = Application.Transpose(Range("B" & Cnt).Resize(, Rws).Value)
   Next Cnt
   Range("B:O").Delete
End Sub
As this deletes columns make sure you try it on a copy
 
Upvote 0
Ok, how about
Code:
Sub AddRowsTranspose()

   Dim Cnt As Long
   Dim Rws As Long
   
   For Cnt = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      Rws = WorksheetFunction.CountA(Rows(Cnt)) - 3
      Range("A" & Cnt + 1).Resize(Rws).EntireRow.Insert
      Range("A" & Cnt).Resize(Rws + 1, 2).FillDown
      Range("C" & Cnt + 1).Resize(Rws).Value = Application.Transpose(Range("D" & Cnt).Resize(, Rws).Value)
      Range("D:O").Delete
   Next Cnt
End Sub
 
Upvote 0
Ok, how about
Code:
Sub AddRowsTranspose()

   Dim Cnt As Long
   Dim Rws As Long
   
   For Cnt = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      Rws = WorksheetFunction.CountA(Rows(Cnt)) - 3
      Range("A" & Cnt + 1).Resize(Rws).EntireRow.Insert
      Range("A" & Cnt).Resize(Rws + 1, 2).FillDown
      Range("C" & Cnt + 1).Resize(Rws).Value = Application.Transpose(Range("D" & Cnt).Resize(, Rws).Value)
      Range("D:O").Delete
   Next Cnt
End Sub

This is working fine with one row not for all rows in the whole table that I mentioned in the first post.
 
Upvote 0
Apologies, just realised that this is posted in the Power BI forum, about which I no nothing.
Whilst this should work with a normal xl sheet, or table, I have no idea if it can be made to work for you.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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