+ Reply to Thread
Results 1 to 7 of 7

VBA Code to transpose data from Sheet 1 to Sheet 2 in a specific order

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    VBA Code to transpose data from Sheet 1 to Sheet 2 in a specific order

    Hi all,

    I'm using Excel 2013 and I need help for a VBA code that will help me transpose data from Sheet 1 of my workbook to its Sheet 2. However, the "transpose" needs to be in a specific order.

    Please have a look at the attached file. My original data is in Sheet 1 and I need it to transpose into the data shown in Sheet 2.

    transpose example.xlsx

    Thanks for your help.

    -Ali

  2. #2
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA Code to transpose data from Sheet 1 to Sheet 2 in a specific order

    Try this:-
    Results sheet2.
    Sub MG24Apr54
    Dim Rng As Range, Dn As Range
    Dim c As Long
    c = 1
    With Sheets("Sheet1")
    Set Rng = .Range(.Range("A2"), .Range("A" & Rows.Count).End(xlUp))
    End With
    Application.ScreenUpdating = False
    For Each Dn In Rng
        With Sheets("Sheet2")
            Dn.Copy
            .Cells(c, 1).Resize(12).PasteSpecial , Transpose:=True
            Dn.Offset(, 1).Resize(, 12).Copy
            .Cells(c, 2).PasteSpecial , Transpose:=True
            Rng(1).Offset(-1, 1).Resize(, 12).Copy
            .Cells(c, 3).PasteSpecial , Transpose:=True
            c = c + 12
        End With
    Next Dn
    Application.ScreenUpdating = True
    End Sub
    Regards Mick

  3. #3
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: VBA Code to transpose data from Sheet 1 to Sheet 2 in a specific order

    Sub xmmx()
    Dim a As Range, x, c As Long, r As Long
    
    Set a = Sheets("sheet1").Cells(1).CurrentRegion
    c = a.Columns.Count - 1
    r = 1
    With Sheets("sheet2")
    For Each x In a.Resize(, 1)
        If Len(x) > 0 Then
            .Cells(r, 1).Resize(c) = x
            .Cells(r, 2).Resize(c) = Application.Transpose(x.Offset(, 1).Resize(, c))
            .Cells(r, 3).Resize(c) = Application.Transpose(a(2).Resize(, c))
            r = r + c
        End If
    Next x
    .Cells(3).Resize(r - 1).NumberFormat = a(2).NumberFormat
    .Cells(3).Resize(r - 1).Font.Bold = True
    End With
    End Sub

  4. #4
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: VBA Code to transpose data from Sheet 1 to Sheet 2 in a specific order

    Kalak, I will have a look at your solution too and report back. Thanks.

  5. #5
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: VBA Code to transpose data from Sheet 1 to Sheet 2 in a specific order

    Thank you MickG! Works beautifully! Just what I was looking for!

  6. #6
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: VBA Code to transpose data from Sheet 1 to Sheet 2 in a specific order

    You're welcome
    NB:- "Kalak's" code is a much better effort !!!!!

  7. #7
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: VBA Code to transpose data from Sheet 1 to Sheet 2 in a specific order

    Thanks Mick.

    I tried them both and both seem fine to me.

    Only if there's a large dataset ...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 5
    Last Post: 07-10-2013, 02:33 PM
  2. [SOLVED] How to copy data range form one sheet to other sheet with desire Reverse Transpose ?
    By nur2544 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-18-2013, 12:30 PM
  3. [SOLVED] Copy and paste data from sheet 2 to sheet 1 based on specific criteria on sheet 1
    By VBADUD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2012, 04:18 AM
  4. Replies: 9
    Last Post: 04-04-2011, 12:03 AM
  5. Pulling data from a sheet into Word in a specific order
    By schallpattern in forum Excel General
    Replies: 0
    Last Post: 06-09-2009, 03:29 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1