Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Integer
Dim j As Integer
'========================================================================|
'Students can only earn points when they are present at school. Likewise, they can |
'not earn points if they are absent from school. If students are at school, they can |
'earn five possible points. If students are absent, they lose only one point. The |
'code below isolates the checkboxes that the user selects if a student is absent. Since |
'there is 6 checkboxes per day per student, and the "Present" checkbox comes first, |
'the code checks to see if every sixth box has been unselected. |
'=========================================================================
For i = 1 To 750 Step 6 'isolates the "Present" checkbox for each day of the week
' per student
If ActiveSheet.OLEObjects("CheckBox" & i).Object.Value = True Then 'if the "Present" checkbox is checked
For j = 1 To 5
ActiveSheet.OLEObjects("CheckBox" & i + j).Object.Enabled = True 'Then the next five sequential checkboxes
Next j 'are enabled so the user can choose to
'deselect any of them as needed.
Else
For j = 1 To 5 'if the "Present" checkbox is not checked
ActiveSheet.OLEObjects("CheckBox" & i + j).Object.Enabled = False 'then the next five sequential checkboxes
ActiveSheet.OLEObjects("CheckBox" & i + j).Object.Value = False 'are unchecked and are disabled. This prevents
Next j 'the students from losing points if they are not
End If 'at school.
Next i
'==========================================================================
'The following code is an attempt to calculate student scores
'==========================================================================
Dim m As Integer
Dim n As Integer
Dim p As Integer
Dim studentNumber As Integer
Dim actualReceived As Integer
Dim psuedoReceived As Integer
Dim presentReceived As Integer
Dim enabledReceived As Integer
For m = 1 To 721 Step 30 '1 student = 30 checkboxes
studentNumber = studentNumber + 1 'keeps track of which student I'm on
For n = m To (m + 29) 'Isolates (a range of) 30 checkboxes per student
If ActiveSheet.OLEObjects("CheckBox" & n).Object.Value = True Then 'Counts all true checkboxes within student's range
psuedoReceived = psuedoReceived + 1
Else
End If
If ActiveSheet.OLEObjects("CheckBox" & n).Object.Enabled = True Then 'Counts all enabled checkboxes within student's range
enabledReceived = enabledReceived + 1
Else
End If
Next n
For p = m To (p + 29) Step 6 'Isolates PRESENT checkboxes
If ActiveSheet.OLEObjects("Checkbox" & n).Object.Value = True Then 'Counts all true "Present" checkboxes" within studnet's range.
presentReceived = presentReceived + 1
Else
End If
Next p
actualReceived = psuedoReceived - presentReceived
Worksheet(1).Cells.(studentNumber - 11, studentNumber -10).Value = actualReceived
Worksheet(1).Cells.(studentNumber - 11, studentNumber - 11).Value = enabledReceived
Next m
End Sub