Advanced Transposing

mike4777

Board Regular
Joined
Apr 12, 2011
Messages
122
Hello all.

I need to take this in column a (imagine real data):


Name
Adress
City/State/Zip
Phone
Repeat 100s of times

<tbody>
</tbody>


and make it into this:

NameAddressCity/State/ZipPhone
NameAddressCity/State/ZipPhone
etc

<tbody>
</tbody>


I know transpose does this for the whole column... but it will make it stretch into row infinity. Not what I'm wanting.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I have seen people come up with solutions more clever than this one, but since no one has responded yet, I will post this one. It should get the job done.
Code:
Sub MyTransposeMacro()

    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim lRow As Long
    Dim r As Long

    Application.ScreenUpdating = False

'   Set worksheet where data currently resides
    Set ws1 = Sheets("Sheet1")
    
'   Set destination worksheet
    Set ws2 = Sheets("Sheet2")
    
'   Set row where first line of data appears on
    r = 1

'   Find last row with data in column A on ws1
    lRow = ws1.Cells(Rows.Count, "A").End(xlUp).Row

'   Loop through all data
    Do Until r > lRow
'       Copy 4 rows
        ws1.Activate
        ws1.Range(Cells(r, "A"), Cells(r + 3, "A")).Copy
'       Paste to destination sheet
        ws2.Activate
        ws2.Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
            False, Transpose:=True
'       Increment counter
        r = r + 4
    Loop
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,942
Members
449,094
Latest member
teemeren

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