+ Reply to Thread
Results 1 to 3 of 3

Thread: Macro to change sheet - Horizontal (Time Allocation) to Veritical (Tablular) format?

  1. #1
    Registered User
    Join Date
    02-03-2011
    Location
    SFO
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro to change sheet - Horizontal (Time Allocation) to Veritical (Tablular) format?

    Hey Gurus, I am trying to reformat a sheet (Excel 2007) from Horizontal (Time allocation) format to Vertical (Tabular) format by using macros. Could you please help me out on this? The macro should be able to run on any number of rows and columns.

    Sample Input Data

    ITEM LOC 1/30/2011 2/6/2011 2/13/2011
    1534 VLLF 5500 11000 5500
    7945 VMED 100 5500 10
    7529 VBOC 20 200 20
    1674 VSAM 5376 0 0

    Expected Output

    ITEM LOC STARTDATE QTY
    1534 VLLF 1/30/2011 5500
    1534 VLLF 2/6/2011 11000
    1534 VLLF 2/13/2011 5500
    7945 VMED 1/30/2011 100
    7945 VMED 2/6/2011 5500
    7945 VMED 2/13/2011 10
    7529 VBOC 1/30/2011 20
    7529 VBOC 2/6/2011 200
    7529 VBOC 2/13/2011 20
    1674 VSAM 1/30/2011 5376
    1674 VSAM 2/6/2011 0
    1674 VSAM 2/13/2011 0

    Please see attached spreadsheet (contain sample data) for both input and expected output.

    Advance thanks all for your help.

    EPalanis
    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,228

    Re: Macro to change sheet - Horizontal (Time Allocation) to Veritical (Tablular) form

    Option Explicit
    
    Sub ReOrganize()
    'Author:    Jerry Beaucaire
    'Date:      9/15/2010
    'Summary:   Reorganize a multivalue column database
    '           into a single value per row database
    '           First column(s) are duplicated
    
    Dim LR  As Long     'last row of data, we start at the bottom
    Dim Col As Long     'column to start reorganization
    Dim Rw  As Long
    Dim Num As Long     'number of values on each row to split down
    Dim Titles As Boolean
    
    'the column to start split down
        Col = 3
    
    'Inquire if data has titles in row1
        Titles = True
    
    Application.ScreenUpdating = False  'speed up execution
    LR = Range("A" & Rows.Count).End(xlUp).Row  'last row with data
    
    'From the bottom up, split data down
        For Rw = LR To (1 - Titles) Step -1
            Num = Cells(Rw, Columns.Count).End(xlToLeft).Column
            If Num > Col Then
                Cells(Rw + 1, "A").Resize(Num - Col).EntireRow.Insert xlShiftDown
                With Range(Cells(Rw, Col + 1), Cells(Rw, Num))
                    .Copy
                    Cells(Rw + 1, Col).PasteSpecial xlPasteAll, Transpose:=True
                    .Clear
                End With
            End If
            If Rw = 1 Then Exit For
        Next Rw
    
    'move extra titles down
        LR = Cells(Rows.Count, Col).End(xlUp).Row
        Range(Cells(2, Col), Cells(LR, Col)).Insert xlShiftToRight
        Range(Cells(1, Col), Cells(1, Num)).Copy
        Range(Cells(2, Col), Cells(LR, Col)).PasteSpecial xlPasteAll, Transpose:=True
        If Titles Then Range(Cells(1, Col + 1), Cells(1, Columns.Count)).Clear
       
    'Duplicate values in beginning column(s)
        With Range("A1", Cells(LR, Col - 1))
            .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
            .Value = .Value
        End With
        Range("C1:D1").Value = [{"StartDate","QTY"}]
        
    Application.ScreenUpdating = True
    End Sub


    The macro above is based on the ReOrganize macro published here:
    _________________
    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
    Registered User
    Join Date
    02-03-2011
    Location
    SFO
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro to change sheet - Horizontal (Time Allocation) to Veritical (Tablular) form

    Thanks Jerry for your help. Much appreciated.

+ 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