Column Data to Rows

Dave Patton

Well-known Member
Joined
Feb 15, 2002
Messages
6,345
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I have about 15000 rows of data in 2 columns
Column A names about 1600 unique names
Column B information from 1 to 19 by name

How do I rearrange the data to multiple columns?

initial information
Student Courses Sep 17 2023.xlsx
AB
1Sep. 17, 2023
2A,AQ1D MDR--08--T-01
3A,AQ2D XHL--08OES-02
4A,As1&2A MEN--08--Y-03
5A,As1&2C MMA--08--Y-03
6A,As1&2G MCE--08--Y-03
7A,AS2D MDR--08PAS-01
8A,As1&2B MFR--08--Y-05
9A,Bs1&2H XAT--12ABD-01
10A,BS1A MFOOD11--S-01
11A,BS1B MGENO12--S-01
12A,BS1C YIPS-1A--S-06
13A,BS1D MNMD-11--S-02
14A,BS2A MODED11--S-03
15A,BS2B MPREC11--S-07
16A,BS2C MPH--11--S-04
17A,BS2D MACLV11B-S-01
Sheet2_2


Required
Student Courses Sep 17 2023.xlsx
ABCDEFGHIJKLM
1NamesCoursesData1data 2data 3data 4data 5data 6data 7data 8 data 9data 10
2A,A7Q1D MDR--08--T-01Q2D XHL--08OES-02s1&2A MEN--08--Y-03s1&2C MMA--08--Y-03s1&2G MCE--08--Y-03S2D MDR--08PAS-01s1&2B MFR--08--Y-05
3A,B9s1&2H XAT--12ABD-01S1A MFOOD11--S-01S1B MGENO12--S-01S1C YIPS-1A--S-06S1D MNMD-11--S-02S2A MODED11--S-03S2B MPREC11--S-07S2C MPH--11--S-04S2D MACLV11B-S-01
Sheet3
Cell Formulas
RangeFormula
A2:A1564A2=UNIQUE(Sheet2_2!A2:A12586)
B2:B3B2=COUNTIF(Sheet2_2!A2:A12500,A2)
Dynamic array formulas.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
There's a number of ways you could do this, here's one option. (Assumes your headers already exist in Sheet3)

VBA Code:
Option Explicit
Sub DaveP()
    Dim ws2 As Worksheet, ws3 As Worksheet
    Set ws2 = Worksheets("Sheet2_2")        '<-- *** Check sheet names ***
    Set ws3 = Worksheets("Sheet3")
    Dim d As Object, i As Long, a, k
    Set d = CreateObject("scripting.dictionary")
    a = ws2.Range("A2", ws2.Cells(Rows.Count, "A").End(xlUp))
    
    ws3.UsedRange.Offset(1).ClearContents
    With ws2
        If .AutoFilterMode Then .AutoFilter.ShowAllData
        With d
            For i = 1 To UBound(a, 1)
                d(a(i, 1)) = 1
            Next i
            For Each k In .keys
                With ws2.Range("A1").CurrentRegion
                    .AutoFilter 1, k
                    .Offset(1, 1).Copy
                    ws3.Cells(Rows.Count, "C").End(xlUp).Offset(1).PasteSpecial Transpose:=True
                    Application.CutCopyMode = False
                    .AutoFilter
                End With
            Next k
        End With
    End With
    
    ws3.Cells(2, 1).Resize(d.Count, 1).Value = Application.Transpose(d.keys)
    With ws3.Range("B2:B" & Cells(Rows.Count, "A").End(xlUp).Row)
        .Formula2R1C1 = "=counta(RC3:RC21)"
        .Value2 = .Value2
    End With
End Sub
 
Upvote 0
an alternative is with Power Query
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Column1"}, {{"Data", each _, type table [Column1=text, Column2=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Data], "I",1,1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Data"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Column2", "I"}, {"Column2", "I"}),
    #"Added Prefix" = Table.TransformColumns(#"Expanded Custom", {{"I", each "Data " & Text.From(_, "en-US"), type text}}),
    #"Pivoted Column" = Table.Pivot(#"Added Prefix", List.Distinct(#"Added Prefix"[I]), "I", "Column2")
in
    #"Pivoted Column"
 
Upvote 0
A formula option
Fluff.xlsm
ABCDEFGHIJKL
1NamesCoursesData1data 2data 3data 4data 5data 6data 7data 8 data 9data 10
2A,A7Q1D MDR--08--T-01Q2D XHL--08OES-02s1&2A MEN--08--Y-03s1&2C MMA--08--Y-03s1&2G MCE--08--Y-03S2D MDR--08PAS-01s1&2B MFR--08--Y-05
3A,B9s1&2H XAT--12ABD-01S1A MFOOD11--S-01S1B MGENO12--S-01S1C YIPS-1A--S-06S1D MNMD-11--S-02S2A MODED11--S-03S2B MPREC11--S-07S2C MPH--11--S-04S2D MACLV11B-S-01
Sheet3
Cell Formulas
RangeFormula
A2:K3A2=LET(u,UNIQUE(FILTER(Sheet2_2!A2:A10000,Sheet2_2!A2:A10000<>"")),c,COUNTIFS(Sheet2_2!A:A,u),HSTACK(u,c,DROP(REDUCE("",u,LAMBDA(x,y,VSTACK(x,EXPAND(TOROW(FILTER(Sheet2_2!B2:B10000,Sheet2_2!A2:A10000=y)),,MAX(c),"")))),1)))
Dynamic array formulas.
 
Upvote 0
Solution
Thanks very much Kevin9999, Alansidman, and Fluff; excellent suggestions.

I marked Fluff's solution as the answer since my friend's file is not an xlsm file.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,108
Messages
6,123,132
Members
449,098
Latest member
Doanvanhieu

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