Transpose Columns to Rows (automatically inserts new rows)

kichkichkich

New Member
Joined
Apr 28, 2012
Messages
2
Hi, I am new here and complete amazed how macro's can make life so much easier but I just can't seem to understand the codes (no programming knowledge).

I would like to have the sports column to be transposed as rows. I have provided a sample file https://skydrive.live.com/redir.aspx?cid=8d2a8d150ed9d1fb&resid=8D2A8D150ED9D1FB!139&parid=8D2A8D150ED9D1FB!105

I can do the job manually by
1. Adjust the other columns (C D E) to about 20 columns away.
2. Use data to columns (delimited by ";").
3. Insert 20 additional rows in between the existing rows.
4. Copy the sports.
5. Special Paste> Transpose.
6. Move on to the next item and repeat 1-5.
7. After finishing, I just use ASAP Utilities to delete the empty rows.

The thing is my file is composed of almost 20k entries and repeating the process would take time.
Can anyone help me with this matter?
It will be surely appreciated. Thank you. :)
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Try this...

Code:
[color=darkblue]Sub[/color] Transpose_Sports()
    [color=darkblue]Dim[/color] v [color=darkblue]As[/color] [color=darkblue]Variant[/color], i [color=darkblue]As[/color] [color=darkblue]Long[/color], j [color=darkblue]As[/color] Long
    Application.ScreenUpdating = [color=darkblue]False[/color]
    [color=darkblue]For[/color] i = Range("B" & Rows.Count).End(xlUp).Row [color=darkblue]To[/color] 2 [color=darkblue]Step[/color] -1
        [color=darkblue]With[/color] Range("B" & i)
            [color=darkblue]If[/color] InStr(.Value, ";") [color=darkblue]Then[/color]
                v = Split(.Value, ";")
                .Offset(1).Resize(UBound(v)).EntireRow.Insert
                [color=darkblue]For[/color] j = 0 [color=darkblue]To[/color] [color=darkblue]UBound[/color](v)
                    .Offset(j).Value = Trim(v(j))
                [color=darkblue]Next[/color] j
            [color=darkblue]Else[/color]
               .Value = Trim(.Value)
            [color=darkblue]End[/color] [color=darkblue]If[/color]
        [color=darkblue]End[/color] [color=darkblue]With[/color]
    [color=darkblue]Next[/color] i
    Application.ScreenUpdating = [color=darkblue]True[/color]
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
 
Upvote 0
Note: 20K rows may take a couple of minutes to transpose. Also, If you have Excel 2003 or earlier, there is a limit of 65536 rows. You cannot transpose 20K rows to more than 65536 rows.
 
Upvote 0
Hi, another noob here...
Firstly, a lot of thanks for posting the question, also great help for the solution.

The above solution answers partially to my problem:
- I would like to copy the text in columns A, C, D and E and paste in the added rows (if any). Also, in my case, the number of columns is 10 i.e. goes up to column K (unlike the example by OP which has 5 columns)
- In my case, as the OP, the column which requires transpose into rows is only one, the difference is that the rest of the data is to be duplicated.

I believe it should not be a big deviation from the above solution, but I don't know how to modify the above solution to fit my needs.
Any help is welcome.

I'm using Excel 2007 on Windows 7. I can also get access to Excel 2016 on Win 7, if needed.

P.S. English is not my first language, so apologies in advance for any mistakes.
 
Upvote 0
@ whataremacros

Make you own question on this forum.

Add a link to this question if you think it is usefull.

Add a small part of your data on the forum and please also add the expected result.
 
Upvote 0
Thanks.
I have done that on this link. Along with sample data.

I posted here initially because I wasn't clear on whether to make a new thread or to reply on an old one.
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,222
Members
453,024
Latest member
Wingit77

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