Calculate GPA Using VBA in Excel – GPA Calculator with Full Code
Learn how to calculate GPA in Microsoft Excel using formulas, credit hours, grade points, VBA functions, macro automation, and an online GPA calculator.
Quick Navigation
Online GPA Calculator What Is GPA? GPA Grade Point Table Excel GPA Formula Full Corrected VBA Code Automatic GPA Macro How to Use VBA in Excel FAQsOnline GPA Calculator
Use this simple GPA calculator to calculate GPA from subjects, credit hours, and grade points. Enter each course credit hour and grade point, then click calculate.
| Course | Credit Hours | Grade Point |
|---|---|---|
| Course 1 | ||
| Course 2 | ||
| Course 3 | ||
| Course 4 | ||
| Course 5 |
Your GPA Result
Total Credit Hours:
Total Quality Points:
Final GPA:
Performance:
What Is GPA?
GPA means Grade Point Average. It is a number that shows the average academic performance of a student. Many schools, colleges, and universities use GPA to measure student results.
The basic GPA formula is simple:
GPA = Total Quality Points / Total Credit Hours
Quality points are calculated by multiplying credit hours by grade points.
Quality Points = Credit Hours × Grade Point
GPA Grade Point Table
| Marks / Percentage | Letter Grade | Grade Point | Remark |
|---|---|---|---|
| 90–100 | A+ | 4.00 | Excellent |
| 85–89 | A | 3.70 | Very Good |
| 80–84 | B+ | 3.30 | Good |
| 75–79 | B | 3.00 | Good |
| 70–74 | C+ | 2.70 | Satisfactory |
| 65–69 | C | 2.30 | Average |
| 60–64 | D | 2.00 | Pass |
| Below 60 | F | 0.00 | Fail |
Calculate GPA Using Excel Formula
Suppose credit hours are in column B and grade points are in column C. Quality points will be in column D.
Step 1: Calculate Quality Points
=B2*C2
Step 2: Calculate Final GPA
=SUM(D2:D6)/SUM(B2:B6)
Alternative Direct Formula
=SUMPRODUCT(B2:B6,C2:C6)/SUM(B2:B6)
Full Corrected VBA Code to Calculate GPA
This VBA function calculates GPA from credit hours and grade points. It is clean, corrected, and safe for beginner Excel users.
Function CalculateGPA(CreditRange As Range, GradePointRange As Range) As Variant
Dim i As Long
Dim TotalCredits As Double
Dim TotalQualityPoints As Double
Dim Credits As Double
Dim GradePoint As Double
If CreditRange.Count <> GradePointRange.Count Then
CalculateGPA = "Range size error"
Exit Function
End If
For i = 1 To CreditRange.Count
If IsNumeric(CreditRange.Cells(i).Value) And IsNumeric(GradePointRange.Cells(i).Value) Then
Credits = CDbl(CreditRange.Cells(i).Value)
GradePoint = CDbl(GradePointRange.Cells(i).Value)
If Credits < 0 Or GradePoint < 0 Or GradePoint > 4 Then
CalculateGPA = "Invalid input"
Exit Function
End If
TotalCredits = TotalCredits + Credits
TotalQualityPoints = TotalQualityPoints + (Credits * GradePoint)
End If
Next i
If TotalCredits = 0 Then
CalculateGPA = "No credits"
Else
CalculateGPA = Round(TotalQualityPoints / TotalCredits, 2)
End If
End Function
How to Use This Function in Excel
If credit hours are in B2:B6 and grade points are in C2:C6, use:
=CalculateGPA(B2:B6,C2:C6)
VBA Code to Convert Marks into Grade Points
This function converts percentage marks into GPA points.
Function MarksToGradePoint(Marks As Double) As Variant
If Marks >= 90 And Marks <= 100 Then
MarksToGradePoint = 4#
ElseIf Marks >= 85 And Marks < 90 Then
MarksToGradePoint = 3.7
ElseIf Marks >= 80 And Marks < 85 Then
MarksToGradePoint = 3.3
ElseIf Marks >= 75 And Marks < 80 Then
MarksToGradePoint = 3#
ElseIf Marks >= 70 And Marks < 75 Then
MarksToGradePoint = 2.7
ElseIf Marks >= 65 And Marks < 70 Then
MarksToGradePoint = 2.3
ElseIf Marks >= 60 And Marks < 65 Then
MarksToGradePoint = 2#
ElseIf Marks >= 0 And Marks < 60 Then
MarksToGradePoint = 0#
Else
MarksToGradePoint = "Invalid Marks"
End If
End Function
Use it like this:
=MarksToGradePoint(A2)
Automatic GPA Macro for Excel
This macro calculates total credit hours, total quality points, and final GPA automatically.
Sub AutoCalculateGPA()
Dim LastRow As Long
Dim i As Long
Dim Credits As Double
Dim GradePoint As Double
Dim TotalCredits As Double
Dim TotalQualityPoints As Double
Dim FinalGPA As Double
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
TotalCredits = 0
TotalQualityPoints = 0
For i = 2 To LastRow
If IsNumeric(Cells(i, "B").Value) And IsNumeric(Cells(i, "C").Value) Then
Credits = CDbl(Cells(i, "B").Value)
GradePoint = CDbl(Cells(i, "C").Value)
If Credits >= 0 And GradePoint >= 0 And GradePoint <= 4 Then
Cells(i, "D").Value = Credits * GradePoint
TotalCredits = TotalCredits + Credits
TotalQualityPoints = TotalQualityPoints + (Credits * GradePoint)
Else
Cells(i, "D").Value = "Invalid"
End If
End If
Next i
If TotalCredits > 0 Then
FinalGPA = TotalQualityPoints / TotalCredits
Range("F2").Value = "Total Credits"
Range("G2").Value = TotalCredits
Range("F3").Value = "Quality Points"
Range("G3").Value = TotalQualityPoints
Range("F4").Value = "Final GPA"
Range("G4").Value = Round(FinalGPA, 2)
MsgBox "GPA calculated successfully: " & Round(FinalGPA, 2), vbInformation
Else
MsgBox "No valid credit hours found.", vbExclamation
End If
End Sub
How to Add VBA Code in Excel
Step 1
Open your Excel GPA sheet.
Step 2
Press ALT + F11 to open VBA Editor.
Step 3
Click Insert → Module.
Step 4
Paste the VBA code into the module.
Step 5
Return to Excel and use the function.
Step 6
Save file as .xlsm.
Example GPA Sheet Structure
| Course | Credit Hours | Grade Point | Quality Points |
|---|---|---|---|
| English | 3 | 4.00 | 12.00 |
| Computer | 3 | 3.70 | 11.10 |
| Math | 3 | 3.30 | 9.90 |
| Science | 2 | 3.00 | 6.00 |
Total Credits: 11 Quality Points: 39 GPA: 3.55
Common VBA GPA Errors and Fixes
| Error | Reason | Fix |
|---|---|---|
| #NAME? | Function name is not recognized | Paste code in Module and check spelling. |
| Macro not working | Macros are disabled | Enable macros in Excel security warning. |
| Code disappeared | File saved as .xlsx | Save as .xlsm file. |
| Wrong GPA | Credit hours or grade points entered incorrectly | Check data and formula ranges. |
Suggested Internal Links
Add these internal links to improve SEO and keep visitors on your website:
Shaigle Home Calculate Grade Using VBA in Excel ICT in Education Excel Tutorial
Frequently Asked Questions
The formula is total quality points divided by total credit hours. In Excel, you can use =SUMPRODUCT(B2:B6,C2:C6)/SUM(B2:B6).
Yes. VBA can calculate GPA automatically using credit hours and grade points.
Quality point means credit hours multiplied by grade points.
Yes. You can edit the grade point table and VBA code according to your institution’s grading policy.
Use .xlsm, which means Excel Macro-Enabled Workbook.
Final Words
Calculating GPA using VBA in Excel is a smart way to automate student result sheets. You can use simple Excel formulas for quick GPA calculation, or you can use VBA code for a professional automated GPA calculator.
This page gives you everything: GPA formula, grade point table, online GPA calculator, VBA function, automatic macro, and troubleshooting guide.
How to insert dash instead of GPA 0(zero)?
ReplyDeleteTry this code place of Zero
DeleteElse
gpa = "-"
End If
End Function
When studying abroad, grading systems can be confusing, especially if you’re not used to weighted assessments. That’s why I always recommend calculadoradenotas.cl. Their international-friendly grade calculator helps break down scores into understandable averages, no matter what system your school uses.
ReplyDelete