Sub CreateWorkbooks()
'Declare (dimension) all variables for this procedure.
Dim rCell As Range 'Represents one or more cells
Dim lLastRow As Long 'Represents the last row in which data has been placed in the document.
Dim oNewBook, oMyBook As Object 'Objects representing the New Workbook for individual student and the master workbook.
Dim sName As String 'Represents the student's name as text
Set oMyBook = ActiveSheet 'Set the oMyBook object to be the Active Sheet
lLastRow = ThisWorkbook.Sheets("Students").UsedRange.Rows.Count 'Assign row number to the last row variable
'This is a "For-Next loop" This one reads: "For each cell in This Workbooks "Students" sheet
'in range A2 through the last row with data in Column A" Do stuff, then go to the next cell.
For Each rCell In ThisWorkbook.Sheets("Students").Range("A2", Range("A" & lLastRow))
If rCell.Value <> "" Then 'If the current cell isn't blank do stuff
sName = rCell.Value 'Assign student's name in current cell to the sName variable
Set oNewBook = Application.Workbooks.Add 'Create a new workbook and set it to the oNewBook object
oMyBook.Range("A1").EntireRow.Copy 'Copy the header row for the master list
oNewBook.Activate 'Make the new book active
ActiveSheet.Range("A1").PasteSpecial 'Paste the header row to the new book
rCell.EntireRow.Copy 'Copy the student's information from that row
oNewBook.Activate 'Make the new book active
ActiveSheet.Range("A2").PasteSpecial 'Paste student's information on line 2 of the new book
On Error GoTo DuplicateName 'If there is an error while saving go to the DuplicateName tag
oNewBook.SaveAs sName 'Save the new book with the student's name
oNewBook.Close 'Close the new book
End If 'Step out of the If statement
NextCell: 'NextCell tag
Next rCell 'Go to the next student (cell)
Exit Sub 'Leave routine after all students are done with before reaching the DuplicateName tag.
DuplicateName: 'DuplicateName tag
'Create message box letting user know that the save operation couldn't complete.
MsgBox "Work for student: " & sName & " could not be saved because a workbook with that name is currently open."
GoTo NextCell 'Leave unsaved workbook open and go to NextCell tag
End Sub