function vba

J

Joost

Hello,

I want to create a function in VBA for example the averge of a range (10
rows). In the following row the same formula but now with a different range
(still 10 rows) but starting from next row.


How can this be done in VBA

Thanks in advanced
 
D

Don Guillett

see if this does it

Sub averagegroupsof10()
For I = 1 To Cells(Rows.Count, "c").End(xlUp).Row Step 10
x = Application.Sum(Cells(I, "c").Resize(10, 1)) / 10
MsgBox x
Next
End Sub
 
J

Joost

thanks lets give it a try
Don Guillett said:
see if this does it

Sub averagegroupsof10()
For I = 1 To Cells(Rows.Count, "c").End(xlUp).Row Step 10
x = Application.Sum(Cells(I, "c").Resize(10, 1)) / 10
MsgBox x
Next
End Sub
 
E

Earl Kiosterud

Joost,

Can you not just use a copied formula:

=AVERAGE(A2:A20)

copied down with the Fill Handle would give:

=AVERAGE(A3:A21)
 
Top