MrJRussell
New Member
- Joined
- Oct 19, 2017
- Messages
- 2
I've read quite a lot on this topic but still can't get my code to work...
I've got a sheet that contains student test scores. Its sorted by grade level and I want to average all the scores over each grade. My macro moves down the grade level column and inserts blank rows to separate all the students in each grade into chunks. I then define a range in the score column that goes from the first to the last record in a particular grade. I then want to insert the average in the blank row below the defined range.
Here is my code:
<code>
Sub FindTheRITAverages()
Dim firstnumber As Integer
Dim secondnumber As Integer
Dim counter As Integer
Dim rangeTop As Integer
Dim Avg As Integer
Dim myRange As Range
counter = 2
rangeTop = 2
Call FindTheBottom(8)
Do Until counter = lastrow
firstnumber = Cells(counter, 8).Value
counter = counter + 1
secondnumber = Cells(counter, 8).Value
If secondnumber <> firstnumber Then
Rows(counter).Select
Selection.Insert Shift:=xlDown
Set myRange = Range(Cells(rangeTop, 10), Cells(counter, 10))
Avg = Applictaion.WorksheetFunction.Average(myRange)
counter = counter + 1
Else
counter = counter + 1
End If
Loop
End Sub
</code>
I get an "Object Required" error. I've also tried to write the =Average() function into the sheet to find the average that way, but I also got an error. Thanks for any help you might provide.
I've got a sheet that contains student test scores. Its sorted by grade level and I want to average all the scores over each grade. My macro moves down the grade level column and inserts blank rows to separate all the students in each grade into chunks. I then define a range in the score column that goes from the first to the last record in a particular grade. I then want to insert the average in the blank row below the defined range.
Here is my code:
<code>
Sub FindTheRITAverages()
Dim firstnumber As Integer
Dim secondnumber As Integer
Dim counter As Integer
Dim rangeTop As Integer
Dim Avg As Integer
Dim myRange As Range
counter = 2
rangeTop = 2
Call FindTheBottom(8)
Do Until counter = lastrow
firstnumber = Cells(counter, 8).Value
counter = counter + 1
secondnumber = Cells(counter, 8).Value
If secondnumber <> firstnumber Then
Rows(counter).Select
Selection.Insert Shift:=xlDown
Set myRange = Range(Cells(rangeTop, 10), Cells(counter, 10))
Avg = Applictaion.WorksheetFunction.Average(myRange)
counter = counter + 1
Else
counter = counter + 1
End If
Loop
End Sub
</code>
I get an "Object Required" error. I've also tried to write the =Average() function into the sheet to find the average that way, but I also got an error. Thanks for any help you might provide.