+ Reply to Thread
Results 1 to 10 of 10

Transposing from multiple lines to single line with multiple related columns

Hybrid View

  1. #1
    Registered User
    Join Date
    08-17-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    38

    Transposing from multiple lines to single line with multiple related columns

    I am not quite sure how to transpose multiple values in a massive spreadsheet. The output is vertical in a table format with unique products per line mapped to an ID. I need to achieve unique products each in their own column per ID. Please see attachment.

    Thanks in advance for your help.
    Attached Files Attached Files

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,641

    Re: help transposing values from multiple lines to a single line with multiple related col

    See attachment.....
    Attached Files Attached Files
    Quang PT

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

    Re: Transposing from multiple lines to single line with multiple related columns

    In the attached file I've assumed that your IDs are not just sequential numbers in reality, so to avoid confusion I've just changed them to letters. I've used two helper columns (D and E) which are coloured blue on a pale yellow background, and put this formula in cell D4:

    =IF(COUNTIF(B$4:B4,B4)=1,MAX(D$3:D3)+1,"-")

    and this in E4:

    =IF(B4="","",B4&"_"&COUNTIF(B$4:B4,B4))

    These can be copied down as far as you like (I've copied to row 20 in the example file) - the first formula helps to identify each unique ID and the second helps to establish each parent_child. To get the unique IDs, you can use this formula in cell G4:

    =IFERROR(INDEX(B:B,MATCH(ROWS($1:1),D:D,0)),"")

    You can use this formula in H4 to get the first product for an ID:

    =IFERROR(INDEX($C:$C,MATCH($G4&"_"&COLUMNS($H:H),$E:$E,0)),"")

    which can be copied across for as many products as you are likely to encounter. These formulae can also be copied down as far as you need them (I've copied to row 13 in the example file).

    You can apply the formatting to the table after you are happy that everything is working as it should.

    Hope this helps.

    Pete
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Transposing from multiple lines to single line with multiple related columns

    a VBA solution
    run with {ctrl} + t in attached file

    Sub TransposeInventory()
    Dim IDrng As Range, ID As Range, output As Range, c As Long, r As Long
    
    Set IDrng = Range("B4", Range("B" & Cells.Rows.Count).End(xlUp))
    Set output = Range("K3")
    
    For Each ID In IDrng
        If ID = idprevious Then
            r = r
            c = c + 1
        Else
            r = r + 1: c = 0
        End If
            idprevious = ID
            output.Offset(r, c) = ID.Offset(, 1)
    Next ID
    
    End Sub
    Attached Files Attached Files
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  5. #5
    Registered User
    Join Date
    08-17-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Transposing from multiple lines to single line with multiple related columns

    Thanks bebo, Pete and kev. Pete, I first saw your reply and it almost works, but somehow is matching and returning data from incorrect IDs. I am not sure exactly what's wrong...so close. bebo, your solution is a couple less steps, although I have forgotten how to get the array formula to execute. kev, I wanted to hold off on adding a script unless it is my last resort, but I appreciate your reply as well.

    Ok, I found the array initial execution with CTRL+SHIFT+ENTER, however, how to paste it down / fill down with it?

    Thank you all sincerely.
    Last edited by Seattlites; 02-20-2017 at 01:59 PM.

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

    Re: Transposing from multiple lines to single line with multiple related columns

    You can see that my solution works in the sample file, so there must be something different in your real file - perhaps you can attach an extract of it which shows where it is going wrong.

    As for copying array formulae, you can just use your usual method(s) - there are many ways.

    Hope this helps.

    Pete

  7. #7
    Registered User
    Join Date
    08-17-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Transposing from multiple lines to single line with multiple related columns

    Thanks Pete. Please see attached.
    Attached Files Attached Files

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

    Re: Transposing from multiple lines to single line with multiple related columns

    I suggest you use this formula in cell F2:

    =IFERROR(INDEX($T:$T,MATCH($E2&"_"&COLUMNS($F:F),$C:$C,0)),"")

    then you can copy this across and down as required.

    Instead of the full-column references (which always start on row 1), you had $C1:$C3042, and as this is copied down the references change on each row as you did not have a $ symbol before the row references.

    Hope this helps.

    Pete

  9. #9
    Registered User
    Join Date
    08-17-2011
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Transposing from multiple lines to single line with multiple related columns

    Thanks again Pete. I normally attempt to reduce the lookup Excel has to perform to less than an entire column when using anything more powerful than VLOOKUP. Even my i7 quad core 16GB machine has trouble churning through INDEX + MATCH functions when applied to thousands of rows.

    In any case, I transposed the location of that absolute reference so thank you for finding that error in my execution.

    Regards,
    Steve

+ 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. Replies: 1
    Last Post: 05-06-2016, 08:22 PM
  2. Replies: 4
    Last Post: 11-20-2014, 10:57 PM
  3. [SOLVED] Transposing single row to multiple columns between workbooks
    By crhoads in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-19-2012, 08:24 AM
  4. [SOLVED] Macro for transposing multiple columns into a single row
    By BBExcelusr in forum Excel - New Users/Basics
    Replies: 7
    Last Post: 09-07-2012, 02:24 PM
  5. Multiple lines of similar data to one single line
    By T_Van in forum Excel General
    Replies: 7
    Last Post: 02-27-2012, 06:03 PM
  6. Replies: 1
    Last Post: 10-16-2009, 09:23 AM
  7. Replies: 1
    Last Post: 03-18-2009, 04:18 PM

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