+ Reply to Thread
Results 1 to 4 of 4

Thread: How to convert data from vertical to horizontal

  1. #1
    Registered User
    Join Date
    01-26-2012
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    11

    How to convert data from vertical to horizontal

    Hi there,

    I have this spreadsheet containing over 7000 x contacts. Each contact consists of up to 38 values (to include first name, surname, title, address etc.). For some reason the first 15 values are displayed horizontally, and beneath, the remaining 23 values are listed vertically. How do I convert the 23 values into a horizontal display? See attached example - 3 x contacts are provided in this example:

    tab 1 'existing' - contains the existing layout
    tab 2 'EndResult' - is what I want to achieve

    There are many merged cells in tab 1 and some shifting required to ensure there are no blank cells.

    Could anyone help?

    Much appreciated.
    Helena
    Attached Files Attached Files

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,222

    Re: How to convert data from vertical to horizontal

    Run this macro on your data, as long as it is exactly in the layout shown:
    Option Explicit
    
    Sub ReformatData()
    Dim RNG As Range, r As Long
    
    Application.ScreenUpdating = False
    Set RNG = Range("A:A").SpecialCells(xlConstants)
    
    For r = 1 To RNG.Areas.Count
        Range("B" & RNG.Areas(r).Cells(1).Row).Resize(6).Copy
        Range("U" & RNG.Areas(r).Cells(1).Row - 1).PasteSpecial xlPasteValues, Transpose:=True
        Range("D" & RNG.Areas(r).Cells(1).Row).Resize(7).Copy
        Range("AA" & RNG.Areas(r).Cells(1).Row - 1).PasteSpecial xlPasteValues, Transpose:=True
        Range("F" & RNG.Areas(r).Cells(1).Row).Resize(10).Copy
        Range("AH" & RNG.Areas(r).Cells(1).Row - 1).PasteSpecial xlPasteValues, Transpose:=True
    Next r
    
    Range("G:G").SpecialCells(xlBlanks).EntireRow.Delete xlShiftUp
    Range("A:E").Delete xlShiftToLeft
    Rows(1).Insert xlShiftDown
    
    For r = 1 To 38
        Cells(1, r) = "Title " & r
    Next r
    Range("A1").Select
    Application.ScreenUpdating = True
    End Sub

    How/Where to install the macro:

    1. Open up your workbook
    2. Get into VB Editor (Press Alt+F11)
    3. Insert a new module (Insert > Module)
    4. Copy and Paste in your code (given above)
    5. Get out of VBA (Press Alt+Q)
    6. Save as a macro-enabled workbook (.xlsm)

    The macro is installed and ready to use. Press Alt-F8 and select ReformatData from the macro list.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,150

    Re: How to convert data from vertical to horizontal

    Hi tiggi and JB

    This is just a test as the thread has zero replies but observably JB has posted??
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

  4. #4
    Registered User
    Join Date
    01-26-2012
    Location
    australia
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: How to convert data from vertical to horizontal

    Wow, this site is amazing! Thanks for the efforts and prompt response JB! And appreciate the follow up check Pike!

    JB, I installed your macro, saved the spreadsheet in the xlsm format, then ran it but I received a runtime error '1004': "No cells found". When I ran it, the cursor was sitting in a new empty sheet in cell a1. Got any further advice?

    Much appreciate your time.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0