Solved

Macro to transpose rows into Columns

Posted on 2013-06-17
3
468 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 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 50

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

749 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