Averaging help

ag1290

New Member
Joined
Jun 8, 2011
Messages
3
Hey everyone,

I have a spreadsheet that has data from A2 to I2, and around 2000 rows. I need to be able to insert a new row every 6 cells and take an average of the preceding 6 cells. If these new values could also be put into a new sheet without any spaces between them, it would be ideal. Is there any way to do this?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try this :-
Results sheet (2)

Code:
[COLOR="Navy"]Sub[/COLOR] MG08Jun10
[COLOR="Navy"]Dim[/COLOR] Lst [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Rw [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] c [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Long,[/COLOR] Ac [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]Integer[/COLOR]
Lst = Range("A" & rows.Count).End(xlUp).row
ReDim ray(1 To Lst, 1 To 9)
[COLOR="Navy"]For[/COLOR] Rw = 2 To Lst [COLOR="Navy"]Step[/COLOR] 6
    c = c + 1
    [COLOR="Navy"]With[/COLOR] Range("A" & Rw)
        [COLOR="Navy"]For[/COLOR] Ac = 1 To 9
            ray(c, Ac) = Application.Average(.Offset(, Ac - 1).Resize(6).value)
        [COLOR="Navy"]Next[/COLOR] Ac
    [COLOR="Navy"]End[/COLOR] With
 [COLOR="Navy"]Next[/COLOR] Rw
Sheets("Sheet2").Range("A1").Resize(c, 9) = ray
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Absolutely perfect.

Thanks Mick, if I needed to slightly tweak it later on, probably to just add more columns, would I need to change much?

But for now, this works perfectly. The reason I needed this was to make sure that the computer generated hourly averages were similar enough to the raw output 10 min averages. I had been using a copy-paste work around to hand calculate averages up to this point, but this is much better.

Best,
ag1290
 
Upvote 0
And if I needed to average 10 rows instead of 6, would I be able to do that?

Thanks Mick

ag1290
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,629
Members
452,933
Latest member
patv

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