+ Reply to Thread
Results 1 to 9 of 9

Formula to shift column headers into rows

  1. #1
    Registered User
    Join Date
    02-05-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Post Formula to shift column headers into rows

    Excel.PNG

    Hey guys, I'm pulling raw data from Adobe Analytics and by default it displays the data in the form of a pivot table. As a result, all of the date values are displayed as column headers as opposed to being categorized in a row.

    I want to change the layout so that the date values show up in the rows under one column (ie. A "date" column). The issue I'm having is that each date value is associated with multiple data points (ex. the date "2018/05/20" is associated with all the data listed underneath it). Is there any way for me to shift the dates into rows while keeping them linked to their associated data points?
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,959

    Re: Formula to shift column headers into rows

    One option is to do Copy/Paste Special+Transpose ---> Dates down rows and Time & age across columns.
    Attached Files Attached Files
    Last edited by protonLeah; 06-06-2018 at 08:21 PM.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    02-05-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Re: Formula to shift column headers into rows

    Thanks for the reply.

    I'm looking to keep the layout of the table exactly the same but just shift the dates into rows while keeping them linked to their associated data points. Transposing the dates into rows puts me in another problem where I have multiple headers (ie. time intervals as one header and age groups as another header). This causes issues when analyzing the data (for example if I wanted to look at the number of individuals between the ages of 18-24 who used the website for 1-5 minutes over the last two weeks, I can't do that since Excel will only capture one row of headers).

    Sorry I should have clarified this in my original post.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,738

    Re: Formula to shift column headers into rows

    The following VBA will transpose your data if you first
    1. Delete column A
    2. Move Time and Age cells down one row.
    3. Delete row1 so that all information starts in cell A1

    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Registered User
    Join Date
    02-05-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Re: Formula to shift column headers into rows

    Thanks alansidman!

    I followed all your steps but when I try to run the VBA code I get an error saying "Subscript out of range"? My VBA knowledge is very limited so I'm probably making a silly error.

    Btw, I'm interested to see what you got on your end when you ran the code. Mind posting a screenshot of it?

    Thanks!

  6. #6
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 365
    Posts
    2,406

    Re: Formula to shift column headers into rows

    For a Date, put this on B27 and copied down
    =IFERROR(INDEX($D$2:$Q$2,ROWS($A$1:A1)),"")

    For Time, put this on C25 and copied cross
    =INDEX($B$3:$B$23,COLUMNS($A$1:A1))

    For Age, put this on C26 and copied cross
    =INDEX($C$3:$C$23,COLUMNS($A$1:A2))

    For Value, put this on C27 and entered as array formula and then copied down and cross
    =IFERROR(INDEX($D$3:$Q$23,0,MATCH($B27,$D$2:$Q$2,0)) INDEX($D$3:$Q$23,MATCH(1,($B$3:$B$23=C$25)*($C$3:$C$23=C$26),0),0),"")
    Attached Files Attached Files

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,738

    Re: Formula to shift column headers into rows

    Here is the file with the Macro executed. I forgot to mention, I renamed Sheet1 and Sheet2 to Data and Result respectively.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    02-05-2017
    Location
    Toronto, Ontario
    MS-Off Ver
    MS Office 2013
    Posts
    4

    Re: Formula to shift column headers into rows

    alansidman that macro did the trick, thanks a million! I feel it's time for me to start learning VBA, super useful in situations like this.

    Thanks everyone for your help with this

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,738

    Re: Formula to shift column headers into rows

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. VBA to move column headers to rows
    By SL1104 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-23-2018, 03:19 PM
  2. Pivot table with multiple rows against the same column headers
    By bocgaroe in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 04-17-2018, 05:37 AM
  3. Check column for empty rows, delete rows shift cells up?
    By B.W.B. in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-06-2017, 12:41 PM
  4. To concatenate column headers if value in rows below is non-blank
    By chibidee in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-17-2015, 06:19 AM
  5. [SOLVED] Add column headers for each 25 rows
    By Pavan.Sada.PS in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-25-2013, 02:32 PM
  6. Shift Rows to Column
    By fareen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-19-2013, 05:03 PM
  7. Help required in Converting Rows to Columns and add Column Headers
    By Swaroopa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2013, 07:15 AM

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