VBA to automatically transpose X rows of data into columns

javajoe

Board Regular
Joined
Nov 7, 2005
Messages
78
Hey folks -

Could really use your help with this one. I have baseline VBA knowledge but not enough to do the following:

I have an Excel worksheet with 200 "logical records" of data, currently represented by ~ 12,000 rows of data in just one column (A). Each logical record is actually 60 rows of the data. So what I need to do is come up with a macro that will do the following and save me from 5 hours worth of mind-numbingly-boring transposing and deleting of rows:

1) Select 60 rows of data.
2) Copy/Paste that selection, then TRANSPOSE onto row one, starting at A1 and going through BH:1 or whatever 60 cells comes out to be horizontally
3) Then Delete the rows of data that were transposed into row 1 columns (basically delete 60 rows)
4) Then select the NEXT 60 rows of data, and repeat the whole process, but this time pasting into row 2 instead of row 1 (A2:BH2).
5) This needs to iterate through the whole worksheet until it cycles through all 12000 rows.
6) The end result will be 200 rows of data, with values in the first 60 columns

Make sense? Any help from those more versed in loops and iterating through a worksheet would be GREATLY appreciated!!!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Try this.
Code:
Sub Trans60()
Dim rng As Range
Dim I As Long
    
    Set rng = Range("A1")
    While rng.Value <> ""
        I = I + 1
        rng.Resize(60).Copy
        Range("B" & I).PasteSpecial Transpose:=True
        Set rng = rng.Offset(60)
        
    Wend
    rng.EntireColumn.Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,575
Messages
6,173,151
Members
452,503
Latest member
AM74

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