Solved

Macro to transpose rows into Columns

Posted on 2013-06-17
3
436 Views
Last Modified: 2013-06-18
I have a spreadsheet with 4 rows that need to be merged into 1 row. On the example spreadsheet attached (in sheet 1), rows 11 to 14 need to be merged into 1 row by adding 3 extra columns between columns D & E, and pasting the contents of cells d12, d13 & d14 into those extra columns. The same needs to happen with rows 15 to 18 and any subsequent groups of 4 rows underneath. The data always starts from row 11.

Sheet 2 in the axample shows the required results.
Excel-Test.xlsx
0
Comment
Question by:Ed_Snowden
3 Comments
 
LVL 24

Accepted Solution

by:
Steve earned 350 total points
ID: 39252826
The following macro code should do the job:

Sub Macro1()

    Columns("E:G").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("D10:G10").Value = Array("Address 1", "Address 2", "Address 3", "Address 4")
    For x = 11 To Range("A65000").End(xlUp).Row
        If Cells(x, 1).MergeCells Then
        
            Cells(x, "E").Value = Cells(x + 1, "D").Value
            Cells(x, "F").Value = Cells(x + 2, "D").Value
            Cells(x, "G").Value = Cells(x + 3, "D").Value
    
            Rows(x + 1 & ":" & x + 3).Delete Shift:=xlUp
        
        End If
    Next x
End Sub

Open in new window

0
 
LVL 48

Expert Comment

by:Rgonzo1971
ID: 39252837
Hi,

You can do it with formulas

Regards
Copy-of-Excel-Test.xlsx
0
 

Author Closing Comment

by:Ed_Snowden
ID: 39255553
Great. Works perfectly. Thanks very much
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now