Can someone please help. I'm almost certain this code has worked fine in the past. I am a teacher and developed this tool to move students and their data from one class to another......
'Moves a student from one set to another
Im happy to share my document...
Thank you in advance,
Ashley
'Moves a student from one set to another
Code:
Sub MoveSet()
DisableCalculation
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim studentToMove As String
studentToMove = Range("MoveName").Value
Dim setToMove As String
setToMove = Range("MoveNewSet").Value
Set setManager = Worksheets("Set Manager")
'Check user has selected a new set.
If setToMove = "" Then
MsgBox "Choose a set."
GoTo complete
End If
'Check user has selected a student.
If studentToMove = "" Then
MsgBox "Choose a student."
GoTo complete
End If
Set NewSheet = Worksheets(setToMove)
Dim newRow As Integer
Dim currentSet As String
Dim currentSheet As Worksheet
Dim currentRow As Integer
'Determine current set of pupil
For Each rCell In Range("Sets")
Set Wks = Worksheets(rCell.Value)
For Each studentNames In Wks.Range("C5:C44")
If studentNames.Value = studentToMove Then
currentSet = rCell.Value
currentRow = studentNames.Row
GoTo checks
End If
Next studentNames
Next rCell
checks:
'Check student was found
If currentRow < 1 Then
MsgBox "Student not found."
GoTo complete
End If
'Check current set and new set are different and return if same
If currentSet = setToMove Then
MsgBox "Student is already in that set."
GoTo complete
End If
'Find next blank row in new set
For Each studentNames In NewSheet.Range("C5:C44")
If studentNames.Value = "" Then
newRow = studentNames.Row
GoTo copyStudent
End If
Next studentNames
'No blank rows found
MsgBox "No blank rows found."
GoTo complete
'Copies student data from one row to the next
copyStudent:
'Copy cell values from old set to new set
Set OldRow = Wks.Rows(currentRow)
UnprotectSheet (Wks)
UnprotectSheet (NewSheet)
For Each oldCell In OldRow.Cells
If Not oldCell.HasFormula Then
'Copy data to new cell
NewSheet.Cells(newRow, oldCell.Column).Value = oldCell.Value
'Delete data from old cell
oldCell.Value = ""
End If
'Only loop columns which will have data in
If oldCell.Column > 150 Then
SortSheet (NewSheet)
SortSheet (Wks)
Set allSheet = Worksheets("All")
UnprotectSheet (allSheet)
allSheet.Activate
allSheet.Range("$A$4:$EP$244").AutoFilter Field:=2, Criteria1:="<>"
allSheet.Range("A1:A1").Select
Wks.Activate
Wks.Range("A1:A1").Select
NewSheet.Activate
NewSheet.Range("A1:A1").Select
setManager.Activate
ProtectSheet (Wks)
ProtectSheet (NewSheet)
ProtectSheet (allSheet)
allSheet.Protect
MsgBox "Move complete."
GoTo complete
End If
Next oldCell
complete:
EnableCalculation
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Im happy to share my document...
Thank you in advance,
Ashley
Last edited by a moderator: