Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Macro to transpose rows into Columns

Posted on 2013-06-17
3
Medium Priority
?
491 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 53

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
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…

636 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