Formula or vba that will split by unique value in column A, then transpose all values with same value in column A in columns b- etc

mnty89

Board Regular
Joined
Apr 1, 2016
Messages
66
Kind of hard to explain in a title but easy to show with sample data.. Basically I will have a series of “ID” values in column A, those will repeat will associated unique values per that ID in column B. I want to format that into a one liner, so that for all of the unique values associated with that ID, it will get pasted in a sort of transposed version in cells B- however many values there are for the ID.

Before and after are below..



Before
ID
Values
11111
abc
11111
def
11111
ghi
11111
jkl
2222
abc
2222
def
2222
ghi
2222
jkl
2222
mno

<tbody>
</tbody>

After

ID
Values
Values
Values
Values
Values
11111
abc
def
ghi
jkl
2222
abc
def
ghi
jkl
mno

<tbody>
</tbody>
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Here is one way:
Code:
Sub MyTranspose()

    Dim myRow As Long
        
    Application.ScreenUpdating = False
    
    myRow = 2
   
    Do Until Cells(myRow, "A") = ""
        If Cells(myRow, "A") = Cells(myRow - 1, "A") Then
            Cells(myRow - 1, Columns.Count).End(xlToLeft).Offset(0, 1) = Cells(myRow, "B")
            Rows(myRow).Delete
        Else
            myRow = myRow + 1
        End If
    Loop
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Here's a formula method:

ABCDEFGHI
1IDValuesIDValues
211111abc11111abcdefghijkl
311111def2222abcdefghijklmno
411111ghi444xy
511111jkl
62222abc
72222def
82222ghi
92222jkl
102222mno
11444x
12444x
13444y
14

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet12

Array Formulas
CellFormula
D2{=IF(D1="","",IFERROR(INDEX($A$2:$A$20,SMALL(IF($A$2:$A$20<>"",IF(COUNTIF($D$1:$D1,$A$2:$A$20)=0,ROW($A$2:$A$20)-ROW($A$2)+1)),1)),""))}
E2{=IF(D2="","",IFERROR(INDEX($B$2:$B$20,SMALL(IF($A$2:$A$20=$D2,IF($B$2:$B$20<>"",IF(COUNTIF($D2:D2,$B$2:$B$20)=0,ROW($B$2:$B$20)-ROW($B$2)+1))),1)),""))}

<thead>
</thead><tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>



Put the D2 formula in, change the references to match your sheet, confirm with Control+Shift+Enter, then drag down as far as needed. Put the E2 formula in the same way, then drag down and to the right as far as needed. The D1:E1 headers are required.
 
Upvote 0
Hello...Sorry to hijack this thread...This code works for what I need, but now I have another file that I need to transpose and this file has 23 columns...Where would I make a change to the code above (that worked perfectly for my file that only had 2 columns)...I need to do the same to the other files that has 23 columns...I'm not sure where to make the range change...

Using this code as mentioned in a post above...

Sub MyTranspose()

Dim myRow As Long

Application.ScreenUpdating = False

myRow = 2

Do Until Cells(myRow, "A") = ""
If Cells(myRow, "A") = Cells(myRow - 1, "A") Then
Cells(myRow - 1, Columns.Count).End(xlToLeft).Offset(0, 1) = Cells(myRow, "B")
Rows(myRow).Delete
Else
myRow = myRow + 1
End If
Loop

Application.ScreenUpdating = True

End Sub
Thank you
 
Last edited:
Upvote 0
To not hijack the thread, please change your source data to 2 columns instead of 23. OK?

Otherwise please start a new thread (& include a link to this one if you want/need to).

regards
 
Upvote 0
Maybe a cross-tab query could be used, too. No formulas & no VBA. Could be like
Code:
TRANSFORM MAX(Values)
SELECT ID
FROM [YourSourceDataTableName]
GROUP BY  ID
PIVOT Values
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,592
Members
449,174
Latest member
chandan4057

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top