?
Solved

Macro to transpose rows into Columns

Posted on 2013-06-17
3
Medium Priority
?
483 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
[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
  • Learn & ask questions
3 Comments
 
LVL 24

Accepted Solution

by:
Steve earned 1400 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 52

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

765 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