+ Reply to Thread
Results 1 to 19 of 19

Convert data from columns to rows with M code

Hybrid View

  1. #1
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: Convert data from columns to rows with formula

    1. Not many Excel forums allow attacments at all, so...

    2. Option 1. VBA.

    3. Option 2 A helper column.

    Which do you prefer?
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,463

    Re: Convert data from columns to rows with formula

    You can put this formula in D3 of the Input Data sheet:

    =IF(B3="","",IF(COUNTIF(B$3:B3,B3)=1,MAX(D$2:D2)+1,MAX(D$2:D2)&"_"&COUNTIF(B$3:B3,B3)))

    and then copy down to the bottom of your data (or beyond, if you wish). In the other sheet you can use these formulae:

    B3: =IFERROR(INDEX('Input Data'!B:B,MATCH(ROWS($1:1),'Input Data'!$D:$D,0)),"")

    C3: =IF(B3="","","|"&INDEX('Input Data'!$C:$C,MATCH(ROWS($1:1),'Input Data'!$D:$D,0))&IFERROR("|"&INDEX('Input Data'!$C:$C,MATCH(ROWS($1:1)&"_2",'Input Data'!$D:$D,0)),"")&IFERROR("|"&INDEX('Input Data'!$C:$C,MATCH(ROWS($1:1)&"_3",'Input Data'!$D:$D,0)),"")&IFERROR("|"&INDEX('Input Data'!$C:$C,MATCH(ROWS($1:1)&"_4",'Input Data'!$D:$D,0)),"")&IFERROR("|"&INDEX('Input Data'!$C:$C,MATCH(ROWS($1:1)&"_5",'Input Data'!$D:$D,0)),""))

    That might look a bit daunting, but it is more straightforward if I show it like this:

    =IF(B3="","","|"&INDEX('Input Data'!$C:$C,MATCH(ROWS($1:1),'Input Data'!$D:$D,0))
    &IFERROR("|"&INDEX('Input Data'!$C:$C,MATCH(ROWS($1:1)&"_2",'Input Data'!$D:$D,0)),"")
    &IFERROR("|"&INDEX('Input Data'!$C:$C,MATCH(ROWS($1:1)&"_3",'Input Data'!$D:$D,0)),"")
    &IFERROR("|"&INDEX('Input Data'!$C:$C,MATCH(ROWS($1:1)&"_4",'Input Data'!$D:$D,0)),"")
    &IFERROR("|"&INDEX('Input Data'!$C:$C,MATCH(ROWS($1:1)&"_5",'Input Data'!$D:$D,0)),""))

    This can accommodate up to 5 items joined together with the | character separating them, but it is quite easy to add more terms if required. If you had a later version of Excel, you could use the TEXTJOIN function to simplify this.

    Copy both formulae down as far as you need them.

    Hope this helps.

    Pete

+ 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. Need a formula to convert to columns to two rows
    By Learner326 in forum Excel General
    Replies: 2
    Last Post: 09-19-2014, 03:46 AM
  2. Excel 2007 : Convert data from columns to rows
    By thandanit in forum Excel General
    Replies: 3
    Last Post: 03-27-2011, 10:55 PM
  3. Excel 2007 : Convert data from columns to rows
    By thandanit in forum Excel General
    Replies: 1
    Last Post: 03-17-2011, 03:41 AM
  4. Convert a set of data from rows to columns
    By naferterri in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-19-2010, 08:33 PM
  5. Convert data from columns to rows
    By ClikClak in forum Excel General
    Replies: 5
    Last Post: 07-19-2010, 12:26 PM
  6. convert data from columns to rows
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-03-2009, 11:14 AM
  7. Convert Columns to rows with DATA
    By raed_237 in forum Excel General
    Replies: 6
    Last Post: 08-05-2008, 04:18 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