Translate Page in your Language

Calculate Grade using VBA in excel

Calculate Grade using VBA in excel




We have an excel sheet with students exam numbers and want to calculate Grade
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 grad(alpha As Double)
If alpha = 4 Then
grad = "A+"
ElseIf alpha < 4 And alpha >= 3.4 Then
grad = "A"
ElseIf alpha < 3.4 And alpha >= 3.1 Then
grad = "B+"
ElseIf alpha < 3.1 And alpha >= 2.8 Then
grad = "B"
ElseIf alpha < 2.8 And alpha >= 2.4 Then
grad = "B-"
ElseIf alpha < 2.4 And alpha >= 2.1 Then
grad = "C+"
ElseIf alpha < 2.1 And alpha >= 1.8 Then
grad = "C"
ElseIf alpha < 1.8 And alpha >= 1.5 Then
grad = "C-"
ElseIf alpha < 1.5 And alpha >= 1 Then
grad = "D"
End If

End Function
After that write procedure name called grad then click save button and then close visual basic editor.
gpa procedure
Now in cell O5 write formula for cell N5 to calculate GPA =gpa(N5),
write grade formula
Excel automatic calculates the grade for given marks.
auto calculate grade
copy this formula for other marks

Google+ Followers