Transpose data from rows to columns

yxz152830

Active Member
Joined
Oct 6, 2021
Messages
393
Office Version
  1. 365
Platform
  1. Windows
Gurus,
I have a data set that looks like this:


A
1​
A
2​
A
3​
B
1​
B
2​
C
1​
C
2​
C
3​
C
4​

I'm hoping to convert the set to this:



A
1​
2​
3​
B
1​
2​
C
1​
2​
3​
4​

is there a way to do it without VBA?
Thanks in advance!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
How about
Fluff.xlsm
ABCDEFGH
1
2A1A123
3A2B12
4A3C1234
5B1
6B2
7C1
8C2
9C3
10C4
Sheet6
Cell Formulas
RangeFormula
D2:H4D2=LET(u,UNIQUE(FILTER(A2:A100,A2:A100<>"")),m,MAX(COUNTIFS(A:A,u)),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,HSTACK(y,TOROW(EXPAND(FILTER(B2:B100,A2:A100=y),m,,"")))))),1))
Dynamic array formulas.
 
Upvote 1
How about
Fluff.xlsm
ABCDEFGH
1
2A1A123
3A2B12
4A3C1234
5B1
6B2
7C1
8C2
9C3
10C4
Sheet6
Cell Formulas
RangeFormula
D2:H4D2=LET(u,UNIQUE(FILTER(A2:A100,A2:A100<>"")),m,MAX(COUNTIFS(A:A,u)),DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,HSTACK(y,TOROW(EXPAND(FILTER(B2:B100,A2:A100=y),m,,"")))))),1))
Dynamic array formulas.
this formula is wayy too complex i rather VBA it. Is pivot table or something gonna work at all?
 
Upvote 0
If you want VBA, why did you ask for a formula?
You will have to wait for someone else to suggest a macro.
 
Upvote 0
Another option with a formula
Fluff.xlsm
ABCDEFGH
1
2A1A123
3A2B12
4A3C1234
5B1
6B2
7C1
8C2
9C3
10C4
Sheet6
Cell Formulas
RangeFormula
D2:D4D2=UNIQUE(A2:A10)
E2:G2,E4:H4,E3:F3E2=TOROW(FILTER($B$2:$B$10,$A$2:$A$10=D2))
Dynamic array formulas.
 
Upvote 1
Solution
An alternative to VBA is Power Query

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Column1"}, {{"Count", each _, type table [Column1=text, Column2=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"INDEX",1,1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Column2", "INDEX"}, {"Column2", "INDEX"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Expanded Custom", {{"INDEX", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Expanded Custom", {{"INDEX", type text}}, "en-US")[INDEX]), "INDEX", "Column2")
in
    #"Pivoted Column"
 
Upvote 0
Been waiting to see what OP wants. Not many solutions if you don't want a macro and formulae are too complex.
It's pretty simple with a macro.
 
Upvote 0
Another option with a formula
Fluff.xlsm
ABCDEFGH
1
2A1A123
3A2B12
4A3C1234
5B1
6B2
7C1
8C2
9C3
10C4
Sheet6
Cell Formulas
RangeFormula
D2:D4D2=UNIQUE(A2:A10)
E2:G2,E4:H4,E3:F3E2=TOROW(FILTER($B$2:$B$10,$A$2:$A$10=D2))
Dynamic array formulas.
this one is simple enough but the transposed data has too many irrelavent data. Is there a way to let the filter formula to filter the specified columns to return and then transpose using torow?
Thanks~!
 
Upvote 0
I don't understand what you mean. The formula produces what you said you wanted.
 
Upvote 0
with macro...

VBA Code:
Sub test()

Set d = CreateObject("Scripting.Dictionary"): Application.ScreenUpdating = False


With Sheets("Sheet1")
Dim table(): table = .Range("A1:B" & .Cells(Rows.Count, 1).End(xlUp).Row).Value

Dim i As Long: For i = LBound(table) To UBound(table)
d(table(i, 1)) = d(table(i, 1)) & table(i, 2) & ","
Next i

.Range("D1").Resize(d.Count) = Application.Transpose(d.keys)
.Range("E1").Resize(d.Count) = Application.Transpose(d.items)
.Range("E1").Resize(d.Count).TextToColumns comma:=True

End With

Application.ScreenUpdating = True: Set d = Nothing: Erase table
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,123,005
Members
449,092
Latest member
masterms

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