This is urgent. Please help!! Summary: The purpose of the VBA program is to coll
ID: 3860464 • Letter: T
Question
This is urgent. Please help!!
Summary: The purpose of the VBA program is to collect data from the user for 5 students and the High test score and Low test score for each student. These values will be displayed on the worksheet. A Function procedure should be called from the Sub to calculate the Average value.
Coding:
Add Option Explicit
Write a Sub procedure named TestScores():
1. Declare necessary variables and constants
2. Use a loop(s)
3. Request from the user 5 student names and a high score and low score for each student (High and Low scores should be whole numbers or rounded to 1 decimal place)
4. Call a Function procedure
5. Average scores should hold decimals
6. Student names, high, low, and average scores should be displayed on the worksheet
Create a Function procedure named AverageScore():
1. Declare necessary variables and constants
2. AverageScore is calculated by adding the high and low then dividing by the number of scores added (2)
Add a message box to show the process is complete
Add comments throughout program
Add a button to the worksheet to run the Sub TestScores. Change the text on the button to START.
This is what I did:
Please tell me what's wrong and fix it for me if there was any mistakes.
Option Explicit
Sub TestScores()
'declare variables
Dim Counter As Integer
Dim Name As String
Dim HScore As Integer
Dim LScore As Integer
'loop
For Counter = 4 To 8
Name = InputBox("Please enter student name.")
Cells(Counter, 1) = Name
Next
For Counter = 4 To 8
HScore = InputBox("Please enter the high score of the student.")
Cells(Counter, 2) = HScore
Next
For Counter = 4 To 8
LScore = InputBox("Please enter the low score of the student.")
Cells(Counter, 3) = LScore
Next
MsgBox ("Data Entry Complete.")
End Sub
Public Function AverageScore(HScore As Integer, LScore As Integer) As Single()
'calculation
AverageScore = (HScore + LScore) / 2
End Function
I still didn't call the function in the sub because I really don't know how. Please help.
Explanation / Answer
Hi,
I have made some code chnages and removed some unwanted lines. Below is the working code to call the function-
Option Explicit
Sub TestScores()
'declare variables
Dim Counter As Integer
Dim Name As String
Dim HScore As Integer
Dim LScore As Integer
Dim val As Integer
'loop
For Counter = 4 To 8
Name = InputBox("Please enter student name.")
Cells(Counter, 1) = Name
HScore = InputBox("Please enter the high score of the student.")
Cells(Counter, 2) = HScore
LScore = InputBox("Please enter the low score of the student.")
Cells(Counter, 3) = LScore
MsgBox ("The average values are updated")
MsgBox (AverageScore(HScore, LScore))
Next
MsgBox ("The average values are updated")
MsgBox (AverageScore(2, 3))
MsgBox ("Data Entry Complete.")
End Sub
Public Function AverageScore(ByVal HScore As Integer, ByVal LScore As Integer) As Single
'calculation
Dim val As Single
AverageScore = (HScore + LScore) / 2
End Function
Regards,
Vinay Singh
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.