Trouble calculating regular averages in Excel
October 18, 2009 8:40 PM
Subscribe
In Excel, how do I calculate the average of every 300 data points in a large data set?
I have ~12000 data points in Excel. I want to take the average of every 300 points (ie. Average(A1:A300), Average(A3001:A6001)). If I write the first formula out, or even write the first few iterations, then drag and fill to complete the rest, it doesn't follow my pattern. It just takes the average starting from the next row in the data (not the row 300 down). As far as my Excel knowledge takes me I'll have to write the formula out 40 times each time I want to analyze a different data set.
Is there a quicker way for Excel to do this?
posted by Midnight Rambler to computers & internet (10 comments total)
1 user marked this as a favorite
Public Sub averageEveryThreeHundred()
Dim intRow As Integer
intRow = whatever the starting row is
Dim lngTotal As Long
Dim intCount As Integer
Dim lngAverage
Do While IsEmpty(Range("column" & intRow).Value = "False"
lngTotal = lngTotal + Range("column" & intRow).Value
intRow = intRow + 300
intCount = intCount + 1
Loop
lngAverage = (lngTotal / intCount)
MsgBox("Counted " & intCount " values, totalled to " & lngTotal & " and averaged to " & lngAverage)
End Sub
To make it put that final average into a cell, add in Range(target).Value = lngAverage
posted by battlebison at 9:11 PM on October 18