Transform horizontal data to vertical data

christian79

New Member
Joined
Oct 24, 2022
Messages
9
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello,

I have a sheet I need to transform from data being stored horizontally, like the following:

Company ID 1DoB 1Name 1DoB 2Name 2DoB 3Name 3
Company ID 2DoB 1Name 1DoB 2Name 2
.....................

Into the following:

Company ID 1DoB 1Name 1
Company ID 1DoB 2Name 2
Company ID 1DoB 3Name 3
Company ID 2DoB 1Name 1
Company ID 2DoB 2Name 2

The data is structured such that the DoB/name entities always occur in as above horizontally (so that offsets can be used).

I've written a VBA script identifying and coloring/counting all the DoBs, but I need one row for each DoB/name entity, in relation to the company ID. Being a one-time operation and thus making performance uninportant, I just loop over all rows and identify things based on offsets.

How can I break each row up into several rows and paste the parts sequentially after eachother?

Thankful for any help!
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Hi & welcome to MrExcel.
Do you need a macro as this can be done with a formula
Fluff.xlsm
ABCDEFGHIJKL
1
2Company ID 1DoB 1Name 1DoB 2Name 2DoB 3Name 3Company ID 1DoB 1Name 1
3Company ID 2DoB 1Name 1DoB 2Name 2Company ID 1DoB 2Name 2
4Company ID 1DoB 3Name 3
5Company ID 2DoB 1Name 1
6Company ID 2DoB 2Name 2
7
Main
Cell Formulas
RangeFormula
J2:L6J2=LET(RngA,A2:A3,RngB,B2:G3,c,COLUMNS(RngB)/2,s,SEQUENCE(ROWS(RngA)*c,,0),hs,HSTACK(INDEX(RngA,INT(s/c)+1),INDEX(RngB,INT(s/c)+1,MOD(s,c)*2+{1,2})),FILTER(hs,INDEX(hs,,2)<>""))
Dynamic array formulas.
 
Upvote 0
Hi & welcome to MrExcel.
Do you need a macro as this can be done with a formula
Fluff.xlsm
ABCDEFGHIJKL
1
2Company ID 1DoB 1Name 1DoB 2Name 2DoB 3Name 3Company ID 1DoB 1Name 1
3Company ID 2DoB 1Name 1DoB 2Name 2Company ID 1DoB 2Name 2
4Company ID 1DoB 3Name 3
5Company ID 2DoB 1Name 1
6Company ID 2DoB 2Name 2
7
Main
Cell Formulas
RangeFormula
J2:L6J2=LET(RngA,A2:A3,RngB,B2:G3,c,COLUMNS(RngB)/2,s,SEQUENCE(ROWS(RngA)*c,,0),hs,HSTACK(INDEX(RngA,INT(s/c)+1),INDEX(RngB,INT(s/c)+1,MOD(s,c)*2+{1,2})),FILTER(hs,INDEX(hs,,2)<>""))
Dynamic array formulas.

Thank you for the reply! Very cool, and somewhat above my formula knowledge level :)

I get #NAME and #UNKNOWN errors in evaluation, though. Any ideas why?
 
Upvote 0
Were you trying this in xl 365?
 
Upvote 0
Assuming data in A1: G2 and further down if need be:

Excel Formula:
=HSTACK(TOCOL(IF(ISEVEN(COLUMN(B1:G2))*(B1:G2<>""),A1:A2,NA()),3),WRAPROWS(TOCOL(B1:G2,1),2)
 
Upvote 0
Ok, you may not have HSTACK yet, how about
Excel Formula:
=LET(RngA,A2:A3,RngB,B2:G3,c,COLUMNS(RngB)/2,s,SEQUENCE(ROWS(RngA)*c,,0),b,INDEX(RngB,INT(s/c)+1,MOD(s,c)*2+{1\2}),hs,choose({1\2\3},INDEX(RngA,INT(s/c)+1),index(b,,1),INDEX(b,,2)),FILTER(hs,INDEX(hs,,2)<>""))
 
Upvote 0
Solution
Ok, you may not have HSTACK yet, how about
Excel Formula:
=LET(RngA,A2:A3,RngB,B2:G3,c,COLUMNS(RngB)/2,s,SEQUENCE(ROWS(RngA)*c,,0),b,INDEX(RngB,INT(s/c)+1,MOD(s,c)*2+{1\2}),hs,choose({1\2\3},INDEX(RngA,INT(s/c)+1),index(b,,1),INDEX(b,,2)),FILTER(hs,INDEX(hs,,2)<>""))
This one worked! Seems like HSTACK is indeed missing for some reason. JvdV, couldn't try your solution for that reason.

Many thanks to both of you!
 
Upvote 0
Glad we could help & thanks for the feedback.
If you are on the semi-annual channel you'll probably get HSTACK (and 13 other functions) in January.
 
Upvote 0
Hi @JvdV , is it possible change the formula for this result ?

Thank you,

1666634423893.png
 
Upvote 0

Forum statistics

Threads
1,216,828
Messages
6,132,957
Members
449,770
Latest member
laptopdoritos

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