Macros/Formulas

wrongful death

New Member
Joined
Apr 8, 2002
Messages
1
I'm trying to create a macro that will average (5) numbers, ie..A1:A5 and have that number shown in B5. Then it will go down the next (5) numbers, ie..A6:A10 and have that number shown in B10. So on and so on and so on for thousands of rows.

Thank for any assistance.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Try the following:

Dim counter As Long
For i = 1 To Int(ActiveSheet.UsedRange.Columns(1).Rows.Count / 5)
counter = counter + 6
Range("a" & counter) = Application.WorksheetFunction.Average(Range("A" & counter - 5), Range("A" & counter - 1))
Next

Should work, but I didn't test it, so post any problems.
 
Upvote 0
On 2002-04-09 12:13, wrongful death wrote:
I'm trying to create a macro that will average (5) numbers, ie..A1:A5 and have that number shown in B5. Then it will go down the next (5) numbers, ie..A6:A10 and have that number shown in B10. So on and so on and so on for thousands of rows.

Thank for any assistance.

Hi,

Quick and easy way without a macro:
In B5, please the following formula

=IF(MOD(ROW(),5)<>0,"",AVERAGE(A1:A5))

and copy down the column

With a macro:
----------------------
Sub average_five()
Dim lastrow As Long, x As Long

lastrow = Cells(Rows.Count, "A").End(xlUp).Row
For x = 5 To lastrow Step 5
Cells(x, 2) = "=AVERAGE(R[-4]C[-1]:RC[-1])"
Next x

End Sub
----------------------------

HTH,
Jay
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,717
Members
448,985
Latest member
chocbudda

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