VBA code to move multiple values associated with one student to specific cell

JLGUZMAN

New Member
Joined
Jun 15, 2018
Messages
8
Hello all,
So I am just starting to venture into Excel VBA and I have been able to patch some things together with the help of this site, but I am now stumped as to how to resolve this one issue. I have a large report that has the workshop segments for a specific student registered that semester listed under their registration information and I need it to be associated with that students record for that specific semester and course. There is also the added issue that it is coming up with duplicates for each of the workshops for that one student, and there is not rhyme or reason as to how many times it duplicates it. I have over 500 students each semester and need to get these reports out to instructors on a timely basis at the start of the semester.

Site ID
Status
Report Month
Type Of Form
Training Date
Course ID
Student ID
Workshops:
SF08891
Rejected
May
Reg
4/15/2018
S088456
W008546
Need workshops that correspond to this student to be moved into Cell H3 without duplications.
(013) Harm Reduction
(013) Harm Reduction
(013) Harm Reduction
(201) Writing Skills
(201) Writing Skills
(201) Writing Skills
SF08564
Rejected
May
Reg
4/15/2018
S054685
W004685
Need workshops that correspond to this student to be moved into Cell H9 without duplications.
(013) Harm Reduction
(013) Harm Reduction
(201) Writing Skills
(201) Writing Skills
(201) Writing Skills
(201) Writing Skills

<tbody>
</tbody>
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hi JLGUZMAN,

Welcome to the MrExcel board.

If what you have posted is the before (I have no idea where cell H3 is), then you might want to post the after. Meaning if we could see what your expected result is (with column and row labels), it would make this a lot easier...
 
Last edited:
Upvote 0
Hello,
Sorry about that. I am new to this whole bloging for help thing.

Here is the image of what I am looking for. The top is the before and the bottom is after. Thank you.

ABCDEFGH
1Site IDStatusMonthType Of FormTraining DateCourse IDStudent IDWorkshops:
2SF08891RejectedMayReg4/15/2018S088456W008546Need workshops that correspond to this student to be moved into Cell H3 without duplications.
3(013) Harm Reduction
4(013) Harm Reduction
5(013) Harm Reduction
6(201) Writing Skills
7(201) Writing Skills
8(201) Writing Skills
9SF08564RejectedMayReg4/15/2018S054685W004685Need workshops that correspond to this student to be moved into Cell H9 without duplications.
10(013) Harm Reduction
11(013) Harm Reduction
12(201) Writing Skills
13(201) Writing Skills
14(201) Writing Skills
15(201) Writing Skills
ABCDEFGH
1Site IDStatusMonthType Of FormTraining DateCourse IDStudent IDWorkshops:
2SF08891RejectedMayReg4/15/2018S088456W008546(013) Harm Reduction, (201) Writing Skills
3SF08564RejectedMayReg4/15/2018S054685W004685(013) Harm Reduction, (201) Writing Skills
<colgroup><col width="64" style="width: 48pt;"> <col width="100" style="width: 75pt; mso-width-source: userset; mso-width-alt: 3657;"> <col width="71" style="width: 53pt; mso-width-source: userset; mso-width-alt: 2596;"> <col width="57" style="width: 43pt; mso-width-source: userset; mso-width-alt: 2084;"> <col width="68" style="width: 51pt; mso-width-source: userset; mso-width-alt: 2486;"> <col width="80" style="width: 60pt; mso-width-source: userset; mso-width-alt: 2925;"> <col width="92" style="width: 69pt; mso-width-source: userset; mso-width-alt: 3364;"> <col width="97" style="width: 73pt; mso-width-source: userset; mso-width-alt: 3547;"> <col width="235" style="width: 176pt; mso-width-source: userset; mso-width-alt: 8594;"> <tbody> </tbody>
 
Upvote 0
Welcome to the MrExcel board!

Try this in a copy of your workbook.

Code:
Sub Workshops()
  Dim rA As Range, c As Range
  Dim d As Object
  Dim lr As Long
  
  Set d = CreateObject("Scripting.Dictionary")
  lr = Range("A" & Rows.Count).End(xlUp).Row
  Application.ScreenUpdating = False
  For Each rA In Range("G2:G" & lr).SpecialCells(xlBlanks).Areas
    d.RemoveAll
    For Each c In Intersect(rA.EntireRow, Columns("A"))
      d(c.Value) = Empty
    Next c
    rA.Cells(0, 2).Value = Join(d.Keys, ", ")
  Next rA
  Range("H2:H" & lr).SpecialCells(xlBlanks).EntireRow.Delete
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you so much. This worked great. I do have one question as I am still learning VBA. If I tried changing the reference column to F by changing "For Each rA In Range("F2:F" & lr).SpecialCells(xlBlanks).Areas" but now it runs and deletes everything in the workbook. Course ID's are also unique and do not duplicate. Am I adjusting the code incorrectly? Thanks again.
 
Upvote 0
Thank you so much. This worked great.
You're welcome, that's great!


I do have one question as I am still learning VBA. If I tried changing the reference column to F by changing "For Each rA In Range("F2:F" & lr).SpecialCells(xlBlanks).Areas" but now it runs and deletes everything in the workbook. Course ID's are also unique and do not duplicate. Am I adjusting the code incorrectly? Thanks again.
The reason that everything (except row 1) was deleted after your change stems from the unchanged line
Rich (BB code):
rA.Cells(0, 2).Value = Join(d.Keys, ", ")
This line writes the workshop data 1 column to the right of the referenced column you changed. That is, it would have over-written the student ID's and then when it came to the line ..
Rich (BB code):
Range("H2:H" & lr).SpecialCells(xlBlanks).EntireRow.Delete
.. all cells would still be blank, and hence deleted.
Try changing the column ref from G to F, but also change that red 2 to 3 and see how it goes.
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,541
Members
449,089
Latest member
davidcom

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