Hi. I'm using Excel 2010 to make a grading program for the teachers at my school.
I've set it up so the form teacher (homeroom teacher) enters in the class enrollment information. Then, the other teachers go in one-by-one and enter their subject grades, etc. The form eventually works as a mail merge to print report cards.
The problem I'm running in to has to do with the optional classes. Each level has, for example, "Option 1" and "Option 2", which represent elective classes. Each student MUST take a class for option 1 and option 2, but their classes may be different (one student may be in Japanese while another is taking Computer Studies). While the classes are different, each option can have only one worksheet (or it gets way too confusing and I can't merge all the data at the end to print reports).
So, when a subject teacher (for an elective) goes in and tries to enter grades for his/her class, s/he sees a form. It goes through the students (names have already been entered by their homeroom teacher). This subject teacher should be able to hit the "Skip" button for all students who are not in his/her class and enter information for those who are. With the code below, I can only skip one student and then get stuck. I realize it has something to do with selecting Cell.(iRow,Y) but I'm not really sure how to get around that problem. I'd like the teacher to be able to skip all the students in the class, if necessary (up to 50 students per class).
I'm including the code for the form, as well as for the buttons. The "cmdSkip" (and possibly "cmdSubmit") button I'm guessing will need to be changed.
Argh. And now I'm getting a Runtime Error 424 (Line 30 -- where it defines the iRow) when I try to hit the cmdSkip. I wasn't getting this error before but lost some changes and can't figure out why I'm getting it now.
I thought I was being clear while explaining this, but please let me know if you need any more information.
---------------------------------------------------
Private Sub cmdClearFormInfo_Click()
'clear the data
Me.txtCourseID.Value = ""
Me.txtCourseName.Value = ""
Me.txtTeacherFirst.Value = ""
Me.txtTeacherLast.Value = ""
Me.txtCourseID.SetFocus
End Sub
Private Sub cmdFinish_Click()
'open General Info form
Worksheets("Menu").Select
'hide this form
Me.Hide
End Sub
Private Sub cmdSkip_Click()
'clear the data
Me.txtAchievement.Value = ""
Me.txtEffort.Value = ""
Me.txtComments.Value = ""
Me.txtAttendance.Value = ""
Me.txtConduct.Value = ""
'load next record
'find first empty row in database
iRow = ws.Cells(Rows.Count, 7) _
.End(xlUp).Offset(1, 0).Row
ws.Cell(iRow, 1).Select
'check to make sure it's not the current record showing in the form
If Me.txtFirst.Value = ActiveCell.Offset(0, 2).Value And Me.txtLast.Value = ActiveCell.Offset(0, 1).Value Then
ActiveCell.Offset(1, 0).Select
End If
Me.txtFirst.Value = ActiveCell.Offset(0, 2).Value
Me.txtLast.Value = ActiveCell.Offset(0, 1).Value
Me.txtCourseID.Value = ActiveCell.Offset(-1, 4).Value
Me.txtCourseName.Value = ActiveCell.Offset(-1, 5).Value
Me.txtTeacherFirst.Value = ActiveCell.Offset(-1, 8).Value
Me.txtTeacherLast.Value = ActiveCell.Offset(-1, 7).Value
Me.cmdSkip.SetFocus
End Sub
Private Sub cmdSubmit_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = ActiveSheet
'find first empty row in database
iRow = ws.Cells(Rows.Count, 7) _
.End(xlUp).Offset(1, 0).Row
'check for empty boxes
If Trim(Me.txtTeacherFirst.Value) = "" Then
Me.txtTeacherFirst.SetFocus
MsgBox "Please enter the course teacher's first name."
ElseIf Trim(Me.txtTeacherLast.Value) = "" Then
Me.txtTeacherLast.SetFocus
MsgBox "Please enter the course teacher's last name."
ElseIf Trim(Me.txtFirst.Value) = "" Then
Me.txtFirst.SetFocus
MsgBox "Please enter the student's last name. If you have no more students to enter, click FINISH."
ElseIf Trim(Me.txtLast.Value) = "" Then
Me.txtLast.SetFocus
MsgBox "Please enter the student's last name. If you have no more students to enter, click FINISH."
ElseIf Trim(Me.txtAchievement.Value) = "" Then
Me.txtAchievement.SetFocus
MsgBox "Please enter the marks earned for achievement this term, in a percentage. This number should be between 0-100 and include coursework, internal assessments, exams, and tests. It should be weighted by importance of each assessment criterion. See supporting document MARKS CALCULATOR.XLSM if you need help calculating this number."
ElseIf Trim(Me.txtAchievement.Value) > 100 Then
Me.txtAchievement.SetFocus
MsgBox "Please enter the marks earned for achievement this term, in a percentage. This number should be between 0-100 and include coursework, internal assessments, exams, and tests. It should be weighted by importance of each assessment criterion. See supporting document MARKS CALCULATOR.XLSM if you need help calculating this number."
ElseIf Trim(Me.txtEffort.Value) = "" Then
Me.txtEffort.SetFocus
MsgBox "Please enter the grade for the student's effort this term. The answer should be one of the following: A, B, C, D, E."
ElseIf Trim(Me.txtAttendance.Value) = "" Then
Me.txtAttendance.SetFocus
MsgBox "Please enter the grade for the student's attendance this term. The answer should be one of the following: A, B, C, D, E."
ElseIf Trim(Me.txtConduct.Value) = "" Then
Me.txtConduct.SetFocus
MsgBox "Please enter the grade for the student's conduct this term. The answer should be one of the following: A, B, C, D, E."
ElseIf Trim(Me.txtComments.Value) = "" Then
Me.txtComments.SetFocus
MsgBox "Please enter some comments about the student's performance and attitude this term. This is an important way to communicate with students and parents about the student's strengths, weaknesses, areas of improvement, etc. The more specific you can be, the more helpful this will be. Do not leave this item blank."
Else
'copy the data to the database
ws.Cells(iRow, 2).Value = Me.txtLast.Value
ws.Cells(iRow, 3).Value = Me.txtFirst.Value
ws.Cells(iRow, 5).Value = Me.txtCourseID.Value
ws.Cells(iRow, 6).Value = Me.txtCourseName.Value
ws.Cells(iRow, 8).Value = Me.txtTeacherLast.Value
ws.Cells(iRow, 9).Value = Me.txtTeacherFirst.Value
ws.Cells(iRow, 11).Value = Me.txtAchievement.Value
ws.Cells(iRow, 12).Value = Me.txtEffort.Value
ws.Cells(iRow, 13).Value = Me.txtAttendance.Value
ws.Cells(iRow, 14).Value = Me.txtConduct.Value
ws.Cells(iRow, 15).Value = Me.txtComments.Value
'clear the data
Me.txtAchievement.Value = ""
Me.txtEffort.Value = ""
Me.txtComments.Value = ""
Me.txtAttendance.Value = ""
Me.txtConduct.Value = ""
'load next record
'find first empty row in database
iRow = ws.Cells(Rows.Count, 7) _
.End(xlUp).Offset(1, 0).Row
Me.txtFirst.Value = ws.Cells(iRow, 3).Value
Me.txtLast.Value = ws.Cells(iRow, 2).Value
Me.txtCourseID.Value = ws.Cells(iRow, 5).Offset(-1, 0).Value
Me.txtCourseName.Value = ws.Cells(iRow, 6).Offset(-1, 0).Value
Me.txtTeacherFirst.Value = ws.Cells(iRow, 9).Offset(-1, 0).Value
Me.txtTeacherLast.Value = ws.Cells(iRow, 8).Offset(-1, 0).Value
Me.cmdSkip.SetFocus
Exit Sub
End If
End If
End Sub
Private Sub UserForm_Activate()
Dim iRow As Long
Dim ws As Worksheet
Set ws = ActiveSheet
'find first empty row in database
iRow = ws.Cells(Rows.Count, 7) _
.End(xlUp).Offset(1, 0).Row
'load next record
'find first empty row in database
iRow = ws.Cells(Rows.Count, 7) _
.End(xlUp).Offset(1, 0).Row
'get course info
If ws.Cells(iRow, 5).Value = "" Then
Me.txtCourseID.Value = ws.Range("E2").Value
Else
Me.txtCourseID.Value = ws.Cells(iRow, 5).Value
End If
If ws.Cells(iRow, 6).Value = "" Then
Me.txtCourseName.Value = ws.Range("F2").Value
Else
Me.txtCourseName.Value = ws.Cells(iRow, 6).Value
End If
Me.txtTeacherFirst.Value = ws.Cells(iRow, 9).Offset(-1, 0).Value
Me.txtTeacherLast.Value = ws.Cells(iRow, 8).Offset(-1, 0).Value
'get first student info
If ws.Cells(iRow, 3).Value = "" Then
MsgBox "You are finished with this class! If you feel this is an error, ask the form teacher to check the enrollment for this class."
Else
Me.txtFirst.Value = ws.Cells(iRow, 3).Value
Me.txtLast.Value = ws.Cells(iRow, 2).Value
End If
Me.txtTeacherFirst.SetFocus
Exit Sub
End Sub
I've set it up so the form teacher (homeroom teacher) enters in the class enrollment information. Then, the other teachers go in one-by-one and enter their subject grades, etc. The form eventually works as a mail merge to print report cards.
The problem I'm running in to has to do with the optional classes. Each level has, for example, "Option 1" and "Option 2", which represent elective classes. Each student MUST take a class for option 1 and option 2, but their classes may be different (one student may be in Japanese while another is taking Computer Studies). While the classes are different, each option can have only one worksheet (or it gets way too confusing and I can't merge all the data at the end to print reports).
So, when a subject teacher (for an elective) goes in and tries to enter grades for his/her class, s/he sees a form. It goes through the students (names have already been entered by their homeroom teacher). This subject teacher should be able to hit the "Skip" button for all students who are not in his/her class and enter information for those who are. With the code below, I can only skip one student and then get stuck. I realize it has something to do with selecting Cell.(iRow,Y) but I'm not really sure how to get around that problem. I'd like the teacher to be able to skip all the students in the class, if necessary (up to 50 students per class).
I'm including the code for the form, as well as for the buttons. The "cmdSkip" (and possibly "cmdSubmit") button I'm guessing will need to be changed.
Argh. And now I'm getting a Runtime Error 424 (Line 30 -- where it defines the iRow) when I try to hit the cmdSkip. I wasn't getting this error before but lost some changes and can't figure out why I'm getting it now.
I thought I was being clear while explaining this, but please let me know if you need any more information.
---------------------------------------------------
Private Sub cmdClearFormInfo_Click()
'clear the data
Me.txtCourseID.Value = ""
Me.txtCourseName.Value = ""
Me.txtTeacherFirst.Value = ""
Me.txtTeacherLast.Value = ""
Me.txtCourseID.SetFocus
End Sub
Private Sub cmdFinish_Click()
'open General Info form
Worksheets("Menu").Select
'hide this form
Me.Hide
End Sub
Private Sub cmdSkip_Click()
'clear the data
Me.txtAchievement.Value = ""
Me.txtEffort.Value = ""
Me.txtComments.Value = ""
Me.txtAttendance.Value = ""
Me.txtConduct.Value = ""
'load next record
'find first empty row in database
iRow = ws.Cells(Rows.Count, 7) _
.End(xlUp).Offset(1, 0).Row
ws.Cell(iRow, 1).Select
'check to make sure it's not the current record showing in the form
If Me.txtFirst.Value = ActiveCell.Offset(0, 2).Value And Me.txtLast.Value = ActiveCell.Offset(0, 1).Value Then
ActiveCell.Offset(1, 0).Select
End If
Me.txtFirst.Value = ActiveCell.Offset(0, 2).Value
Me.txtLast.Value = ActiveCell.Offset(0, 1).Value
Me.txtCourseID.Value = ActiveCell.Offset(-1, 4).Value
Me.txtCourseName.Value = ActiveCell.Offset(-1, 5).Value
Me.txtTeacherFirst.Value = ActiveCell.Offset(-1, 8).Value
Me.txtTeacherLast.Value = ActiveCell.Offset(-1, 7).Value
Me.cmdSkip.SetFocus
End Sub
Private Sub cmdSubmit_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = ActiveSheet
'find first empty row in database
iRow = ws.Cells(Rows.Count, 7) _
.End(xlUp).Offset(1, 0).Row
'check for empty boxes
If Trim(Me.txtTeacherFirst.Value) = "" Then
Me.txtTeacherFirst.SetFocus
MsgBox "Please enter the course teacher's first name."
ElseIf Trim(Me.txtTeacherLast.Value) = "" Then
Me.txtTeacherLast.SetFocus
MsgBox "Please enter the course teacher's last name."
ElseIf Trim(Me.txtFirst.Value) = "" Then
Me.txtFirst.SetFocus
MsgBox "Please enter the student's last name. If you have no more students to enter, click FINISH."
ElseIf Trim(Me.txtLast.Value) = "" Then
Me.txtLast.SetFocus
MsgBox "Please enter the student's last name. If you have no more students to enter, click FINISH."
ElseIf Trim(Me.txtAchievement.Value) = "" Then
Me.txtAchievement.SetFocus
MsgBox "Please enter the marks earned for achievement this term, in a percentage. This number should be between 0-100 and include coursework, internal assessments, exams, and tests. It should be weighted by importance of each assessment criterion. See supporting document MARKS CALCULATOR.XLSM if you need help calculating this number."
ElseIf Trim(Me.txtAchievement.Value) > 100 Then
Me.txtAchievement.SetFocus
MsgBox "Please enter the marks earned for achievement this term, in a percentage. This number should be between 0-100 and include coursework, internal assessments, exams, and tests. It should be weighted by importance of each assessment criterion. See supporting document MARKS CALCULATOR.XLSM if you need help calculating this number."
ElseIf Trim(Me.txtEffort.Value) = "" Then
Me.txtEffort.SetFocus
MsgBox "Please enter the grade for the student's effort this term. The answer should be one of the following: A, B, C, D, E."
ElseIf Trim(Me.txtAttendance.Value) = "" Then
Me.txtAttendance.SetFocus
MsgBox "Please enter the grade for the student's attendance this term. The answer should be one of the following: A, B, C, D, E."
ElseIf Trim(Me.txtConduct.Value) = "" Then
Me.txtConduct.SetFocus
MsgBox "Please enter the grade for the student's conduct this term. The answer should be one of the following: A, B, C, D, E."
ElseIf Trim(Me.txtComments.Value) = "" Then
Me.txtComments.SetFocus
MsgBox "Please enter some comments about the student's performance and attitude this term. This is an important way to communicate with students and parents about the student's strengths, weaknesses, areas of improvement, etc. The more specific you can be, the more helpful this will be. Do not leave this item blank."
Else
'copy the data to the database
ws.Cells(iRow, 2).Value = Me.txtLast.Value
ws.Cells(iRow, 3).Value = Me.txtFirst.Value
ws.Cells(iRow, 5).Value = Me.txtCourseID.Value
ws.Cells(iRow, 6).Value = Me.txtCourseName.Value
ws.Cells(iRow, 8).Value = Me.txtTeacherLast.Value
ws.Cells(iRow, 9).Value = Me.txtTeacherFirst.Value
ws.Cells(iRow, 11).Value = Me.txtAchievement.Value
ws.Cells(iRow, 12).Value = Me.txtEffort.Value
ws.Cells(iRow, 13).Value = Me.txtAttendance.Value
ws.Cells(iRow, 14).Value = Me.txtConduct.Value
ws.Cells(iRow, 15).Value = Me.txtComments.Value
'clear the data
Me.txtAchievement.Value = ""
Me.txtEffort.Value = ""
Me.txtComments.Value = ""
Me.txtAttendance.Value = ""
Me.txtConduct.Value = ""
'load next record
'find first empty row in database
iRow = ws.Cells(Rows.Count, 7) _
.End(xlUp).Offset(1, 0).Row
Me.txtFirst.Value = ws.Cells(iRow, 3).Value
Me.txtLast.Value = ws.Cells(iRow, 2).Value
Me.txtCourseID.Value = ws.Cells(iRow, 5).Offset(-1, 0).Value
Me.txtCourseName.Value = ws.Cells(iRow, 6).Offset(-1, 0).Value
Me.txtTeacherFirst.Value = ws.Cells(iRow, 9).Offset(-1, 0).Value
Me.txtTeacherLast.Value = ws.Cells(iRow, 8).Offset(-1, 0).Value
Me.cmdSkip.SetFocus
Exit Sub
End If
End If
End Sub
Private Sub UserForm_Activate()
Dim iRow As Long
Dim ws As Worksheet
Set ws = ActiveSheet
'find first empty row in database
iRow = ws.Cells(Rows.Count, 7) _
.End(xlUp).Offset(1, 0).Row
'load next record
'find first empty row in database
iRow = ws.Cells(Rows.Count, 7) _
.End(xlUp).Offset(1, 0).Row
'get course info
If ws.Cells(iRow, 5).Value = "" Then
Me.txtCourseID.Value = ws.Range("E2").Value
Else
Me.txtCourseID.Value = ws.Cells(iRow, 5).Value
End If
If ws.Cells(iRow, 6).Value = "" Then
Me.txtCourseName.Value = ws.Range("F2").Value
Else
Me.txtCourseName.Value = ws.Cells(iRow, 6).Value
End If
Me.txtTeacherFirst.Value = ws.Cells(iRow, 9).Offset(-1, 0).Value
Me.txtTeacherLast.Value = ws.Cells(iRow, 8).Offset(-1, 0).Value
'get first student info
If ws.Cells(iRow, 3).Value = "" Then
MsgBox "You are finished with this class! If you feel this is an error, ask the form teacher to check the enrollment for this class."
Else
Me.txtFirst.Value = ws.Cells(iRow, 3).Value
Me.txtLast.Value = ws.Cells(iRow, 2).Value
End If
Me.txtTeacherFirst.SetFocus
Exit Sub
End Sub