Averaging every 5 cells

macros

New Member
Joined
Jul 29, 2009
Messages
7
I have an excel sheet with time in column A and scientific data in column B. I would like to get a macro that averages every 5 values/cells. E.G. B2 through B6, B7 through B11, etc

THANK YOU
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Sub AverageEm()

Dim Skip As Integer
Dim Looper
Skip = 5

For Looper = 1 To Range(("B1"), Range(("B1")).End(xlDown)).Rows.Count Step Skip

Range("B5").Offset(Looper - 1, 1) = "Average = "
With Range("B5").Offset(Looper - 1, 2).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

Range("B5").Offset(Looper - 1, 2) = WorksheetFunction.Average(Range(Cells(Looper, 2), Cells(Looper + 4, 2)))

Next Looper

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

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