VBA Write a sub called StudentAve that calculates the student average of each st
ID: 3850621 • Letter: V
Question
VBA Write a sub called StudentAve that calculates the student average of each student in the below table. Note that cell A5 is a named cell given the name "GradeTable" corresponding to a fixed location on the table. Your sub should have the following features: A loop to loop through each student in the class. A way to exit the loop after the last student has been processed. (Cell below last name is blank.) For each student, read in the grades directly from the excel cells using the range method. Calculate the homework average and test average for each student and use the range method to output the following to the spreadsheet: Homework average Test average Final average If any particular student is failing (overall average is less than 60), output to the user via a message box a statement that the student is failing and the overall average before program loops to the next student. Use the next page to write the VBA code for your function.Explanation / Answer
Hi,
Please find below the code-
Private Sub CommandButton1_Click()
Dim x As Integer
Dim hwk_avg As Double
Dim test_avg As Double
hwk_avg = 0
Application.ScreenUpdating = False
NumRows = Range("A1", Range("A1").End(xlDown)).Rows.Count
Range("A1").Select
For x = 6 To NumRows
hwk_avg = ((CDbl(Cells(x, 2).Value) + CDbl(Cells(x, 3).Value) + CDbl(Cells(x, 4).Value)) / 3)
test_avg = (CDbl(Cells(x, 5).Value) + CDbl(Cells(x, 6).Value)) / 2
ActiveCell.Offset(1, 0).Select
Next x
MsgBox (hwk_avg)
MsgBox (test_avg)
Application.ScreenUpdating = True
End Sub
Regards,
Vinay Singh
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.