Solved

Macro to transpose rows into Columns

Posted on 2013-06-17
477 Views
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
Question by:Ed_Snowden
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 24

Accepted Solution

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
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
``````
0

LVL 51

Expert Comment

ID: 39252837
Hi,

You can do it with formulas

Regards
Copy-of-Excel-Test.xlsx
0

Author Closing Comment

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

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month1 day, 18 hours left to enroll