bethaneesmith
New Member
- Joined
- Nov 12, 2014
- Messages
- 4
The first part of this problem required me to make a userform to ask about a class year, course info, and the grade a student received in the class. I have done that. The second part that I'm having trouble with is the gpa calculation based off the user input pulled from the userform. I need to ask the user if they want to calculate a yearly gpa (based off freshman, sophomore, etc. years) or a final gpa (all grades from all years). I know in my head what I need to do but I don't really know how to write the code for it. I've included what I've come up with so far. Any help would be awesome!! Sorry if the format is bad. I'm new to this and VBA.
Sub GPACalculator() Dim schoolyear As String
Dim grade As String
Dim gradeval As Integer
Dim LR As Long
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR
schoolyear = Cells(i, 1)
grade = Cells(i, 4)
InputBox ("Would you like to calculate a yearly or final GPA?")
If yearly Then
Select Case schoolyear
Case Is = "Freshman"
If grade = "A" Then
gradeval = 4
MsgBox "GPA for Freshman is 4.0."
Cells(i, 5).Value = "4.0"
ElseIf grade = "B" Then
gradeval = 3
MsgBox "GPA for Freshman is 3.0."
Cells(i, 5).Value = "3.0"
ElseIf grade = "C" Then
gradeval = 2.5
MsgBox "GPA for Freshman is 2.5."
Cells(i, 5).Value = "2.5"
ElseIf grade = "D" Then
gradeval = 2
MsgBox "GPA for Freshman is 2.0."
Cells(i, 5).Value = "2.0"
Else: grade = "F"
gradeval = 0
MsgBox "GPA For Freshman is 0.0."
Cells(i, 5).Value = "0.0"
End If
Case Is = "Sophomore"
If grade = "A" Then
gradeval = 4
MsgBox "GPA for Sophomore is 4.0."
Cells(i, 5).Value = "4.0"
ElseIf grade = "B" Then
gradeval = 3
MsgBox "GPA for Sophomore is 3.0."
Cells(i, 5).Value = "3.0"
ElseIf grade = "C" Then
gradeval = 2.5
MsgBox "GPA for Sophomore is 2.5."
Cells(i, 5).Value = "2.5"
ElseIf grade = "D" Then
gradeval = 2
MsgBox "GPA for Sophomore is 2.0."
Cells(i, 5).Value = "2.0"
Else: grade = "F"
gradeval = 0
MsgBox "GPA For Sophomore is 0.0."
Cells(i, 5).Value = "0.0"
End If
Case Is = "Junior"
If grade = "A" Then
gradeval = 4
MsgBox "GPA for Junior is 4.0."
ElseIf grade = "B" Then
gradeval = 3
MsgBox "GPA for Junior is 3.0."
ElseIf grade = "C" Then
gradeval = 2.5
MsgBox "GPA for Junior is 2.5."
ElseIf grade = "D" Then
gradeval = 2
MsgBox "GPA for Junior is 2.0."
Else: grade = "F"
gradeval = 0
MsgBox "GPA For Junior is 0.0."
End If
Case Is = "Senior"
If grade = "A" Then
gradeval = 4
MsgBox "GPA for Senior is 4.0."
ElseIf grade = "B" Then
gradeval = 3
MsgBox "GPA for Senior is 3.0."
ElseIf grade = "C" Then
gradeval = 2.5
MsgBox "GPA for Senior is 2.5."
ElseIf grade = "D" Then
gradeval = 2
MsgBox "GPA for Senior is 2.0."
Else: grade = "F"
gradeval = 0
MsgBox "GPA For Senior is 0.0."
End If
End Select
Next i
End Sub
Sub GPACalculator() Dim schoolyear As String
Dim grade As String
Dim gradeval As Integer
Dim LR As Long
LR = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
For i = 2 To LR
schoolyear = Cells(i, 1)
grade = Cells(i, 4)
InputBox ("Would you like to calculate a yearly or final GPA?")
If yearly Then
Select Case schoolyear
Case Is = "Freshman"
If grade = "A" Then
gradeval = 4
MsgBox "GPA for Freshman is 4.0."
Cells(i, 5).Value = "4.0"
ElseIf grade = "B" Then
gradeval = 3
MsgBox "GPA for Freshman is 3.0."
Cells(i, 5).Value = "3.0"
ElseIf grade = "C" Then
gradeval = 2.5
MsgBox "GPA for Freshman is 2.5."
Cells(i, 5).Value = "2.5"
ElseIf grade = "D" Then
gradeval = 2
MsgBox "GPA for Freshman is 2.0."
Cells(i, 5).Value = "2.0"
Else: grade = "F"
gradeval = 0
MsgBox "GPA For Freshman is 0.0."
Cells(i, 5).Value = "0.0"
End If
Case Is = "Sophomore"
If grade = "A" Then
gradeval = 4
MsgBox "GPA for Sophomore is 4.0."
Cells(i, 5).Value = "4.0"
ElseIf grade = "B" Then
gradeval = 3
MsgBox "GPA for Sophomore is 3.0."
Cells(i, 5).Value = "3.0"
ElseIf grade = "C" Then
gradeval = 2.5
MsgBox "GPA for Sophomore is 2.5."
Cells(i, 5).Value = "2.5"
ElseIf grade = "D" Then
gradeval = 2
MsgBox "GPA for Sophomore is 2.0."
Cells(i, 5).Value = "2.0"
Else: grade = "F"
gradeval = 0
MsgBox "GPA For Sophomore is 0.0."
Cells(i, 5).Value = "0.0"
End If
Case Is = "Junior"
If grade = "A" Then
gradeval = 4
MsgBox "GPA for Junior is 4.0."
ElseIf grade = "B" Then
gradeval = 3
MsgBox "GPA for Junior is 3.0."
ElseIf grade = "C" Then
gradeval = 2.5
MsgBox "GPA for Junior is 2.5."
ElseIf grade = "D" Then
gradeval = 2
MsgBox "GPA for Junior is 2.0."
Else: grade = "F"
gradeval = 0
MsgBox "GPA For Junior is 0.0."
End If
Case Is = "Senior"
If grade = "A" Then
gradeval = 4
MsgBox "GPA for Senior is 4.0."
ElseIf grade = "B" Then
gradeval = 3
MsgBox "GPA for Senior is 3.0."
ElseIf grade = "C" Then
gradeval = 2.5
MsgBox "GPA for Senior is 2.5."
ElseIf grade = "D" Then
gradeval = 2
MsgBox "GPA for Senior is 2.0."
Else: grade = "F"
gradeval = 0
MsgBox "GPA For Senior is 0.0."
End If
End Select
Next i
End Sub