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

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
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,608
Messages
6,120,500
Members
448,968
Latest member
screechyboy79

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