GPA Calculator Help

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
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
To start, you'll want to move the InputBox prompt outside of the For....Next loop. Otherwise the user will be prompted once for each row of data.
 
Upvote 0

Forum statistics

Threads
1,215,242
Messages
6,123,830
Members
449,127
Latest member
Cyko

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top