Translate Page in your Language

Calculate GPA using VBA in excel


We have an excel sheet with students exam numbers and want to calculate GPA
calculate gpa and grade
You can access the VBA environment in Excel 2007-2013 by opening the Microsoft Visual Basic for Applications window.
First, be sure that the DEVELOPER tab is visible in the toolbar in Excel.
The DEVELOPER tab is the toolbar that has the buttons to open the VBA editor. To display the Developer tab, click on FILE in the menu bar and select Options from the drop down menu. Open developer-toolbar


When the Excel Options window appears, click on the Customize Ribbon option on the left.
Excel options
Click on the Developer checkbox under the list of Main Tabs on the right. Then click on the OK button.
Developer Toolbar
Select the DEVELOPER tab from the toolbar at the top of the screen. Then click on the Visual Basic option in the Code group.
Developer page visible
Now the Microsoft Visual Basic for Applications editor should appear and you can insert your VBA code.
from menu select insert then click Module.
insert module
The Visual Basic for Applications editor should appear now insert function GPA.
module
Function gpa(res As Double)
If res <= 100 And res > 84 Then
gpa = 4
ElseIf res <= 84 And res > 83 Then
gpa = 3.9
ElseIf res <= 83 And res > 82 Then
gpa = 3.75
ElseIf res <= 82 And res > 81 Then
gpa = 3.6
ElseIf res <= 81 And res > 80 Then
gpa = 3.5
ElseIf res <= 80 And res > 79 Then
gpa = 3.4
ElseIf res <= 79 And res > 78 Then
gpa = 3.3
ElseIf res <= 78 And res > 76 Then
gpa = 3.2
ElseIf res <= 76 And res > 74 Then
gpa = 3.1
ElseIf res <= 74 And res > 73 Then
gpa = 3
ElseIf res <= 73 And res > 71 Then
gpa = 2.9
ElseIf res <= 71 And res > 69 Then
gpa = 2.8
ElseIf res <= 69 And res > 68 Then
gpa = 2.7
ElseIf res <= 68 And res > 67 Then
gpa = 2.6
ElseIf res <= 67 And res > 65 Then
gpa = 2.5
ElseIf res <= 65 And res > 64 Then
gpa = 2.4
ElseIf res <= 64 And res > 63 Then
gpa = 2.3
ElseIf res <= 63 And res > 61 Then
gpa = 2.2
ElseIf res <= 61 And res > 60 Then
gpa = 2.1
ElseIf res <= 60 And res > 59 Then
gpa = 2
ElseIf res <= 59 And res > 58 Then
gpa = 1.9
ElseIf res <= 58 And res > 57 Then
gpa = 1.8
ElseIf res <= 57 And res > 56 Then
gpa = 1.7
ElseIf res <= 56 And res > 55 Then
gpa = 1.6
ElseIf res <= 55 And res > 54 Then
gpa = 1.5
ElseIf res <= 54 And res > 53 Then
gpa = 1.4
ElseIf res <= 53 And res > 52 Then
gpa = 1.3
ElseIf res <= 52 And res > 51 Then
gpa = 1.2
ElseIf res <= 51 And res > 50 Then
gpa = 1.1
ElseIf res <= 50 And res > 49 Then
gpa = 1
Else
gpa = 0
End If
End Function
After that write procedure name called gpa then click save button and then close visual basic editor.
gpa procedure

Google+ Followers