Convert multiple rows with different number of columns into a single row

tornavida

New Member
Joined
Oct 20, 2022
Messages
2
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hello everyone,

First of all, if this is a very simple issue I apologize for keeping the board busy but I couldn't find a way out of this very simple looking problem:

before.png



I have 4 rows each of which has different numbers of columns containing data. I want to convert them into a single row, without merging the cells. So I want the output to be something like:


after.png



So the formula basically has to add the first row, when there is no more data left on that column, it should start from the beginning of the next row and keep adding the same way with all the rows. I tried to make it work with OFFSET and INDEX but couldn't get out of the mess. I would be glad if you could show me how to do this. A solution that would work with more rows would be very welcome.

Thank you!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
A power query solution

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Transposed Table" = Table.Transpose(#"Removed Columns")
in
    #"Transposed Table"
 
Upvote 0
Paste this formula to B1 and pull to the right.
Excel Formula:
=TRIM(MID(SUBSTITUTE(TEXTJOIN(",",1,$B$2:$G$4),",",REPT(" ",99)),(COLUMN(A$1:A1)-1)*99+1,99))
 
Last edited by a moderator:
Upvote 0
Solution
Hi & welcome to MrExcel.
Another option in B7 dragged across
Excel Formula:
=FILTERXML("<k><m>"&TEXTJOIN("</m><m>",,$B$2:$G$4)&"</m></k>","//m[string-length()>0]["&COLUMNS($B7:B7)&"]")
 
Upvote 0
Cheers everyone, that was super helpful and quick! After some little tweaks for my data set, any of them work perfectly. Thanks a lot!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

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