Move Vertical to Horizontal

CindyCas

New Member
Joined
Jul 28, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have a list of students and grades for multiple courses. I need to change this so that all of the classes/grades for each student are listed in the same row instead of multiple rows.

This is what I have.
Student IDstudent namecourseCodecurrent scorefinal scoreunposted current scoreunposted final score
2212174740​
Student AFoundations ClinicalClinical
0​
0​
2212174740​
Student AFoundations of Practical NursingPN104
79.04​
13.09​
79.04​
13.09​
2212174740​
Student AIV TherapyIV202
86.67​
13​
86.67​
13​
2109162949​
Student BCareer ReadinessCD101
73.28​
7.46​
73.28​
7.46​
2109162949​
Student BNursing IIIPN301
88​
66.03​
88​
66.03​
2109162949​
Student BClinical Term 4 -AkhereCLINICAL
100​
63.16​
100​
63.16​

So instead of having the student listed multiple times/multiple rows the student would just be listed once with all the courses in the same row.

This is what I need:
1690563514108.png
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Lists
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
How about
Excel List Example.xlsx
ABCDEFGHIJKLMNOPQRST
1Student IDstudent namecourseCodecurrent scorefinal scoreunposted current scoreunposted final score
22212174740Student AFoundations ClinicalClinical00
32212174740Student AFoundations of Practical NursingPN10479.0413.0979.0413.09
42212174740Student AIV TherapyIV20286.671386.6713
52109162949Student BCareer ReadinessCD10173.287.4673.287.46
62109162949Student BNursing IIIPN3018866.038866.03
72109162999Student CClinical Term 4 -AkhereCLINICAL10063.1610063.16
8
9
10
11
12
13
142212174740Student AFoundations ClinicalClinical0000Foundations of Practical NursingPN10479.0413.0979.0413.09IV TherapyIV20286.671386.6713
152109162949Student BCareer ReadinessCD10173.287.4673.287.46Nursing IIIPN3018866.038866.03
162109162999Student CClinical Term 4 -AkhereCLINICAL10063.1610063.16
Sheet1
Cell Formulas
RangeFormula
A14:T16A14=LET(u,UNIQUE(A2:B7),m,MAX(COUNTIFS(A2:A7,TAKE(u,,1)))*6,HSTACK(u,DROP(REDUCE("",TAKE(u,,1),LAMBDA(x,y,VSTACK(x,EXPAND(TOROW(FILTER(C2:H7,A2:A7=y)),,m,"")))),1)))
Dynamic array formulas.
 
Upvote 0
Hi @CindyCas
Welcome to the MrExcel forum. Please accept my warmest greetings and sincere hope that all is well.

If it's few records, the following version has quite short code:
VBA Code:
Sub student_v1()
  Dim sh1 As Worksheet, sh2 As Worksheet
  Dim c As Range, f As Range
  Dim lc As Long
  
  Set sh1 = Sheets("Sheet1")    'Fit to your Source sheet name
  Set sh2 = Sheets("Sheet2")    'Fit to your Target sheet name
  
  sh2.Cells.ClearContents
  sh2.Range("A1").Resize(1, 8).Value = sh1.Range("A1").Resize(1, 8).Value
  For Each c In sh1.Range("A2", sh1.Range("A" & Rows.Count).End(3))
    Set f = sh2.Range("A:A").Find(c.Value, , xlValues, xlWhole, , , False)
    If f Is Nothing Then
      sh2.Range("A" & Rows.Count).End(3)(2).Resize(1, 8).Value = c.Resize(1, 8).Value
    Else
      lc = sh2.Cells(f.Row, Columns.Count).End(1).Column + 1
      sh2.Cells(1, lc).Resize(1, 6).Value = sh1.Range("C1").Resize(1, 6).Value
      sh2.Cells(f.Row, lc).Resize(1, 6).Value = c.Offset(, 2).Resize(1, 6).Value
    End If
  Next
End Sub


But if there are hundreds of records, this version is faster:

VBA Code:
Sub student_v2()
  Dim sh1 As Worksheet
  Dim dic As Object
  Dim a As Variant, b As Variant, c As Variant, ky As Variant
  Dim i&, j&, k&, nMax&, y&, nRow&, nCol&
  
  Set sh1 = Sheets("Sheet1")
  a = sh1.Range("A1:H" & sh1.Range("A" & Rows.Count).End(3).Row).Value
  Set dic = CreateObject("Scripting.Dictionary")
  
  For i = 2 To UBound(a, 1)
    dic(a(i, 1)) = dic(a(i, 1)) + 1
    If dic(a(i, 1)) > nMax Then nMax = dic(a(i, 1))
  Next
  ReDim b(1 To dic.Count, 1 To (6 * nMax) + 2)
  
  dic.RemoveAll
  For i = 2 To UBound(a, 1)
    If Not dic.exists(a(i, 1)) Then
      y = y + 1
      dic(a(i, 1)) = y & "|" & 3
      b(y, 1) = a(i, 1)
      b(y, 2) = a(i, 2)
    End If
    nRow = Split(dic(a(i, 1)), "|")(0)
    nCol = Split(dic(a(i, 1)), "|")(1)
    
    k = 3
    For j = nCol To nCol + 5
      b(nRow, j) = a(i, k)
      k = k + 1
    Next
    
    nCol = nCol + 6
    dic(a(i, 1)) = nRow & "|" & nCol
  Next

  With Sheets("Sheet2")
    .Range("A1").Resize(1, 8).Value = sh1.Range("A1").Resize(1, 8).Value
    k = 9
    For j = 2 To nMax
      .Cells(1, k).Resize(1, 6).Value = sh1.Range("c1").Resize(1, 6).Value
      k = k + 6
    Next
    .Range("A2").Resize(UBound(b, 1), UBound(b, 2)).Value = b
  End With
End Sub

You decide which macro to use.
------------------------------------

HOW TO INSTALL MACROs
If you are new to macros, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. To use the macro, go back to the worksheet with your data on it and press ALT+F8, select the macro name (student_v1 o student_v2) from the list that appears and click the Run button. The macro will execute and perform the action(s) you asked for. If you will need to do this again in this same workbook, and if you are using XL2007 or above, make sure you save your file as an "Excel Macro-Enabled Workbook (*.xlsm) and answer the "do you want to enable macros" question as "Yes" or "OK" (depending on the button label for your version of Excel) the next time you open your workbook.


--------------
Let me know the result and I'll get back to you as soon as I can.
Cordially
Dante Amor
--------------
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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