Free Microsoft Excel Training Videos

Project in Excel using macro

How to enter data and calculate grades automatically

Excel Project
As soon as the Excel macro is run the headers appear.
Then the user gets an inputbox to enter the name of the student.
After entering the name, the user is asked to enter the marks of the student in 5 subjects of 100 marks each using the 'for' loop.
Applying standard calculation code and 'if' function the total, percentage and grade of the student is calculated.
If the student achieves an 'A' grade, this is formatted to highlight his achievement in red color. In fact, a custom form has been created for the user in Excel to automate grade calculations.
The entire code has been reproduced below.
Watch the video below to see the macro in action:




Macro Code for ready reference:
Sub calculating_grades()
'ask for the student's name
'initialize the starting row
x = 1
Cells(x, 1).Value = "Name"
Cells(x, 1).Font.Bold = True
Cells(x, 2).Value = "Marks1"
Cells(x, 2).Font.Bold = True
Cells(x, 3).Value = "Marks2"
Cells(x, 3).Font.Bold = True
Cells(x, 4).Value = "Marks3"
Cells(x, 4).Font.Bold = True
Cells(x, 5).Value = "Marks4"
Cells(x, 5).Font.Bold = True
Cells(x, 6).Value = "Marks5"
Cells(x, 6).Font.Bold = True
Cells(x, 7).Value = "Total"
Cells(x, 7).Font.Bold = True
Cells(x, 8).Value = "Percentage"
Cells(x, 8).Font.Bold = True
Cells(x, 9) = "Grade"
Cells(x, 9).Font.Bold = True
Line1:
x = x + 1
StudentName = InputBox("Enter the student's name")
Cells(x, 1).Value = StudentName
'assume 5 subjects
'initialize marks, total
marks = 0
total = 0
For counter = 1 To 5
marks = InputBox("Enter the student's marks in the 5 subjects")
Cells(x, (counter + 1)).Value = marks
total = total + marks
Cells(x, 7).Value = total
Dim percentage As Double
percentage = 0#
percentage = total / 5
Cells(x, 8).Value = percentage
If percentage >= 90 Then
Grade = "A"
ElseIf percentage >= 80 Then
Grade = "B"
ElseIf percentage >= 70 Then
Grade = "C"
ElseIf percentage >= 60 Then
Grade = "D"
Else
Grade = "Work Harder!"
End If
Cells(x, 9).Value = Grade
Next counter
If Grade = "A" Then
Cells(x, 9).Font.ColorIndex = 3
Cells(x, 9).Font.Bold = True
End If
question = InputBox("Do you want to continue? Enter 'y' or 'Y' for Yes.")
If question = "y" Or question = "Y" Then
GoTo Line1
Else
End
End If
End Sub


Project in Excel using macro