Transposing Data in Excel

SanketDash

New Member
Joined
Apr 14, 2015
Messages
4
I need help in transposing data from rows to columns. Currently, my data is looking like this:
Y11234678910111213
Y21234678910111213
Y31234678910111213
Y41234678910111213

<tbody>
</tbody>

I want my data to look like this

Y11234
Y21234
Y31234
Y41234
Y16789
Y26789
Y36789
Y46789
Y110111213
Y210111213
Y310111213
Y410111213

<tbody>
</tbody>

I have mentioned the same numbers in each row for convenience purpose ony. In the actual data-set, the rows have different values.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Your problem is a little confusing since the example doesn't support what you are actually asking for.

If the issue is that you truly want to "transpose" the data from rows to columns then there is a paste special option to do just that. Copy your data, then left click somewhere else (so as not to copy over any other data when your table is transposed), right click, paste special, transpose (Excel 2010, not sure if the path is the same on other versions, be surprised if it's vastly different though).

If that's not what your after you'll have to give a clearer explanation or a more accurate model. As the data truly transposed from rows to columns would look like:

Code:
Y1    Y2    Y3    Y4
1      1      1      1
2      2      2      2
3      3      3      3
etc...
 
Upvote 0
"If that's not what your after you'll have to give a clearer explanation or a more accurate model. As the data truly transposed from rows to columns would look like:"

Thanks for the reply. I used the word transpose because I could not find a better word. Its more like arranging data in a specific format automatically.

The example mentions the required format.
 
Upvote 0
Okay, that changes things.

Probably a number of possible solutions but it will depend on any patterns in your data or required arrangement that we can construct rules around.

You could do it with a vlookup based on the Y1 - Y4, but the column which you wanted to return from the vlookup would change every four rows (as it switches back to Y1), so you'd need to add some way of the formula choosing the return column dynamically.

Other option would be some VBA, which will almost certainly take longer than a formula, and if it's not a repeatable process and this took longer to develop and test than just moving it manually (copy/paste) and using checksums to prove nothing has been lost/altered in the move, then it would be a false economy to spend the time developing a VBA solution.
 
Upvote 0
Hi,

are there many columns of data currently?

Is this going to be a routine process?

If not it might be easier to simply do a few copy and paste to reorder your data

Regards,
Wynn
 
Upvote 0
@TheGlovener

VLOOKUP is a good option. It slipped my mind.

@Wynn
There are thousands of such blocks. Hence, I need an automatic way.
 
Upvote 0
As I say, it looks like you will need a way of calculating the return column from the VBA.

I would probably set up some adjacent column to hold the return colulmn as a hardcoded number for the first 4 rows.

So assuming we are only working with one column of the vertical data in your "transposed" table something like:




A
B
C
C (shown as formula)
E
1
Y1
=vlookup(A1, DataTable, C1, 0)
2
2 (first one hardcoded as column 2
2
Y2
=vlookup(A2, DataTable, C2, 0
2
=if(A2="Y1", C1 + 1, C1)
3
Y3
=vlookup(A3, DataTable, C3, 0)
2
=if(A3="Y1", C2 + 1, C2)
4
Y4
=vlookup(A4, DataTable, C4, 0)
2
=if(A4="Y1", C3 + 1, C3)
5
Y1
=vlookup(A5, DataTable, C5, 0)
3
=if(A5="Y1", C4 + 1, C4)
6
Y2
=vlookup(A6, DataTable, C6, 0)
3
=if(A6="Y1", C5 + 1, C5)
7
Y3
=vlookup(A7, DataTable, C7, 0)
3
=if(A7="Y1", C6 + 1, C6)
8
Y4
=vlookup(A8, DataTable, C8, 0)
3
=if(A8="Y1", C7 + 1, C7)

<tbody>
</tbody>


Obviously you'll need to expand that to have 4 formula and four column references but I think that should work.

So we use the occurrence of the string "Y1" in column A to trigger a change to the column number to be returned in the vlookup which we calculate independently in the adjacent column.
 
Last edited:
Upvote 0
As I say, it looks like you will need a way of calculating the return column from the VBA.

I would probably set up some adjacent column to hold the return colulmn as a hardcoded number for the first 4 rows.

So assuming we are only working with one column of the vertical data in your "transposed" table something like:




ABCC (shown as formula)E
1Y1=vlookup(A1, DataTable, C1, 0)22 (first one hardcoded as column 2
2Y2=vlookup(A2, DataTable, C2, 02=if(A2="Y1", C1 + 1, C1)
3Y3=vlookup(A3, DataTable, C3, 0)2=if(A3="Y1", C2 + 1, C2)
4Y4=vlookup(A4, DataTable, C4, 0)2=if(A4="Y1", C3 + 1, C3)
5Y1=vlookup(A5, DataTable, C5, 0)3=if(A5="Y1", C4 + 1, C4)
6Y2=vlookup(A6, DataTable, C6, 0)3=if(A6="Y1", C5 + 1, C5)
7Y3=vlookup(A7, DataTable, C7, 0)3=if(A7="Y1", C6 + 1, C6)
8Y4=vlookup(A8, DataTable, C8, 0)3=if(A8="Y1", C7 + 1, C7)

<tbody>
</tbody>


Obviously you'll need to expand that to have 4 formula and four column references but I think that should work.

So we use the occurrence of the string "Y1" in column A to trigger a change to the column number to be returned in the vlookup which we calculate independently in the adjacent column.


Thanks a lot.
 
Upvote 0

Forum statistics

Threads
1,216,030
Messages
6,128,407
Members
449,448
Latest member
Andrew Slatter

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