Averaging A Named Range

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.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hard to sort your problem with no knowledge of your data layout or the called subroutine. If you post a representative sample of your data that can be copied and pasted into Excel, and a description of what you want to achieve, someone here can give you a working VBA solution.
 
Upvote 0
Hard to sort your problem with no knowledge of your data layout or the called subroutine. If you post a representative sample of your data that can be copied and pasted into Excel, and a description of what you want to achieve, someone here can give you a working VBA solution.

Thanks for your quick response.

The data layout looks something like this:
Grade Level (Column H)Test (Column I)Score (Column J)
2Reading121
2Math111
2Science114
2Reading115
2Math123
3Reading133
3Math123
3Science145
3Reading121

<tbody>
</tbody>

The subroutine is just to find the row number of the last record, so I can exit the Do loop.

Public lastrow As Integer


Sub FindTheBottom(columnnumber)
Dim basement As Long
Cells(1, columnnumber).Select
Do Until basement = 1048576
Selection.End(xlDown).Select
basement = ActiveCell.Row
Loop
Selection.End(xlUp).Select
lastrow = ActiveCell.Row
'MsgBox (lastrow)
End Sub

The error is thrown here: Avg = Applictaion.WorksheetFunction.Average(myRange)
 
Upvote 0

Forum statistics

Threads
1,215,527
Messages
6,125,337
Members
449,218
Latest member
Excel Master

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top