+ Reply to Thread
Results 1 to 8 of 8

Transpose duplicate rows into columns

  1. #1
    Registered User
    Join Date
    03-03-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Transpose duplicate rows into columns

    Hi,

    I've been using this solution found on this forum here (the one in post 2):

    http://www.excelforum.com/excel-prog...o-columns.html

    However, this solution only works for a 2 column setup. Many times I have multiple columns and need to copy all of those contents into new column. See my attached document for an example.

    If anyone knows how to alter the current macro or has a new one that would be a great help. At the moment I'm having to concatenate the columns, move stuff around, and then run the macro and it is a pain.

    Any assistance would be great. Cheers.
    Attached Files Attached Files
    Last edited by Ochenden; 05-30-2011 at 12:15 AM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Transpose duplicate rows into columns

    Hi

    Here goes.

    Please Login or Register  to view this content.
    rylo

  3. #3
    Registered User
    Join Date
    03-03-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Transpose duplicate rows into columns

    Hi rylo,

    That worked perfectly. However, can I be pain and change my request slightly? Is it possible for it to not copy the 1st column again?

    Like so in the attachment. I hate to be such a pain. I fiddled with the code but no success.

    Cheers
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    03-03-2011
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Transpose duplicate rows into columns

    Hey, I got it working by changing the code like this

    Please Login or Register  to view this content.
    Change For i = 1 to For i = 2 and deleted this row
    .Range(.Range("A2"), .Range("A2").End(xlDown)).Delete shift:=xlToLeft

    Thanks for your help champ.

  5. #5
    Registered User
    Join Date
    10-15-2014
    Location
    Los Angeles
    MS-Off Ver
    2010
    Posts
    3

    Re: Transpose duplicate rows into columns

    This doesn't work for me like your attached files show.

  6. #6
    Registered User
    Join Date
    10-15-2014
    Location
    Los Angeles
    MS-Off Ver
    2010
    Posts
    3

    Re: Transpose duplicate rows into columns

    I'm sorry, your example works for me. Now I need to figure it out with my data. Thanks!

  7. #7
    Registered User
    Join Date
    08-08-2016
    Location
    NJ, USA
    MS-Off Ver
    2016 / OFFICE 365
    Posts
    4

    Re: Transpose duplicate rows into columns

    Hi everyone - I have been bouncing back and forth between this thread and this one http://www.excelforum.com/excel-prog...o-columns.html as well. I too have multiple rows that begin with duplicate numbers (Column A) and then unique data in columns B-J which I want to combine into one row.
    If I try the formula, I get a "runtime error 9 subscript out of range".

    How can I tweak this so that it will put row A, 1,2,3,4,5 and row B,6,7,8 - and pull the data from ALL of the columns into the row????

    (Although in some cases the data is the same in any one of columns B-J for more than one row. (In otherwords, column C is name, D is supplier - so C may be the same for row 2 and 3, but D would be different).

    Editing to add further info: I have had luck with the script:

    Sub x()

    Dim rInput As Range, oDic As Object, sNames() As String, vInput()
    Dim i As Long, nIndex As Long

    Set rInput = Range("A1", Range("B65536").End(xlUp))
    vInput = rInput.Value
    ReDim sNames(1 To UBound(vInput, 1), 1 To 2)
    Set oDic = CreateObject("Scripting.Dictionary")

    With oDic
    For i = 1 To UBound(vInput, 1)
    If Not .Exists(vInput(i, 1)) Then
    nIndex = nIndex + 1
    sNames(nIndex, 1) = vInput(i, 1)
    sNames(nIndex, 2) = vInput(i, 2)
    .Add vInput(i, 1), nIndex
    ElseIf .Exists(vInput(i, 1)) Then
    sNames(.Item(vInput(i, 1)), 2) = sNames(.Item(vInput(i, 1)), 2) & ", " & vInput(i, 2)
    End If
    Next i
    End With

    Cells(1, "H").Resize(nIndex, 2) = sNames
    ' The line below if you want the words in separate columns
    ' otherwise they are in a single cell, separated by commas
    Cells(1, "I").Resize(nIndex).TextToColumns , comma:=True

    End Sub


    -------------
    works for pulling the data from column b onto the same row.... how do i modify this to pull data from column b, c, d, and e for example?
    Last edited by sethboyardee; 08-08-2016 at 03:03 PM.

  8. #8
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Transpose duplicate rows into columns

    Hello sethboyardee,

    Since you are still a new Member of this Great Forum, it might be possible that you may have forgotten the following;


    No. 1. Unfortunately your post does not comply with Rule 2 of our Forum RULES. Do not post a question in the thread of another member -- start your own thread.

    If you feel an existing thread is particularly relevant to your need, provide a link to the other thread in your new thread.

    Old threads are often only monitored by the original participants. New threads not only open you up to all possible participants again, they typically get faster response, too.

    No. 2.Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

+ 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