+ Reply to Thread
Results 1 to 8 of 8

Excel 2007 : Transposing data with mirror flip

Hybrid View

  1. #1
    Registered User
    Join Date
    04-07-2010
    Location
    Vancouver, Washington
    MS-Off Ver
    Excel 2007
    Posts
    16

    Question Transposing data with mirror flip

    Hi All,
    I just registered. I hope to share a LOT of information with others and every once in a while ask a question that I just can't seem to wrap or warp my head around. This is one of those cases... DUN DUN

    How I arrived here:
    I have a trending history of data going back, weekly, to Jan 2009. The data is a weekly report I produce and I have been okay with manually adding an extra column to the end of the data as, "at the time", it was faster than building a macro to do it for me. The report has become a bit crazy now and I will be adding a macro to do this for me, however, I want to add the data by inserting a column at the beginning instead. Not a big deal, except for all the data I already have trended.

    Question:
    I want to transpose the information so that the most recent date is now at the beginning of the columns and the oldest date is at the end. Is there an easy way to do this?

    I played with the Transpose function of the paste values however that is not working. I was thinking of building a vlookup and hlookup to grab the data based on the first row of dates and build it that way, however, that means I still have to manually put in the dates for each week I want to pull in data from.

    Ok, I will shut it now for your responses. Thanks so much in advance!

    Jim (aka AnalystnotAnal)
    Excel Intermediate
    VB Novice (not a beginner)
    Last edited by AnalystnotAnal; 04-07-2010 at 07:00 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Transposing data with mirror flip

    Hi Jim.

    Create a sample workbook showing the actual data layout BEFORE and what you want it to be AFTER. With that, it should be simple enough to create a macro to do that for you automatically.

    Click GO ADVANCED and use the paperclip icon to post up your workbook.
    _________________
    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
    04-07-2010
    Location
    Vancouver, Washington
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Transposing data with mirror flip

    Absolutely. I should have done that in the first place. Thanks.
    Attached Files Attached Files
    If I have been helpful please click the reputation icon (old fashioned scale) to add to my reputation. Thank you!

    Jim (aka AnalystnotAnal)
    Excel Intermediate
    VB Novice (not a beginner)

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Transposing data with mirror flip

    Hi Jim, perhaps try:
    Sub Macro1()
    Dim i As Long, j As Long, k As Long
    Application.ScreenUpdating = False
    i = Cells(1, Columns.Count).End(xlToLeft).Column
    k = 1
    For j = i - 1 To 1 Step -1
        Cells(1, i).EntireColumn.Cut
        Cells(1, k).Insert Shift:=xlToRight
        k = k + 1
    Next j
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    End Sub
    Assumes dates are in row 1 (the "Before" and "After" headings are removed).

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Transposing data with mirror flip

    Try this:
    Option Explicit
    
    Sub Mirror()
    Dim Cols As Long, Col As Long
    Application.ScreenUpdating = False
    
    Cols = Cells.Find("*", Cells(Rows.Count, Columns.Count), SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Column - 1
    
    For Col = Cols To 1 Step -1
        Columns(Col).Copy Cells(2, Columns.Count).End(xlToLeft).Offset(-1, 1)
    Next Col
    
    Range("A1", Cells(1, Cols)).EntireColumn.Delete xlShiftToLeft
    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

    The macro is installed and ready to use. Press Alt-F8 and select it from the macro list.

  6. #6
    Registered User
    Join Date
    04-07-2010
    Location
    Vancouver, Washington
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Transposing data with mirror flip

    JB - Your code works the same as Pauls? Or how does it differ? I was able to make Pauls work, however, I have to copy the data to a blank worksheet so it is looking at A1 through column.count. Can I modify this to work at wherever my cursor is positioned? For example, almost always the data begins on a worksheet at D3. And I don't want to copy the entire column, just the cells in the row.count that you see in my example. They don't get any longer. So for example D3 : BQ19 would be the amount of data to flip ends on.

  7. #7
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: Transposing data with mirror flip

    Try this (it uses the active cell as the starting point, so be sure to have that cell selected or you're going to have a mess of your data):
    Sub Macro2()
    Dim startCol As Long, endCol As Long, startRow As Long, endRow As Long
    Dim i As Long
    Application.ScreenUpdating = False
    startCol = ActiveCell.Column
    startRow = ActiveCell.Row
    endCol = Cells(ActiveCell.Row, Columns.Count).End(xlToLeft).Column
    endRow = startRow + 16
    
    For i = endCol - 1 To startCol Step -1
        Range(Cells(startRow, endCol), Cells(endRow, endCol)).Cut
        Cells(startRow, startCol).Insert Shift:=xlToRight
        startCol = startCol + 1
    Next i
    
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    End Sub

  8. #8
    Registered User
    Join Date
    04-07-2010
    Location
    Vancouver, Washington
    MS-Off Ver
    Excel 2007
    Posts
    16

    Re: Transposing data with mirror flip

    Worked like a charm. Thanks Paul and JB. Great teamwork!

+ 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.6.0 RC 1