Average dynamic data cells over a one hour period?

F

forextrader

How do I sample numbers data from a dynamic cell in Excel each minute and
show an average of this accumulated data for a one hours time, with the
running average result showing in another cell(updating every minute)?
 
B

Bob Phillips

Here is one way

Option Explicit

Dim nStart As Date
Dim nTime As Date

Sub StartCounter()
nStart = Now
nTime = Now + TimeSerial(0, 1, 0)
Application.OnTime nTime, "RunCounter"
End Sub

Sub RunCounter()
Static RunningTotal

RunningTotal = RunningTotal + Range("H1").Value
Range("H2").Value = "Running: " & RunningTotal
If Now > nStart + TimeSerial(0, 3, 0) Then
nTime = Now + TimeSerial(0, 1, 0)
Application.OnTime nTime, "RunCounter"
Else
Application.OnTime nTime, "RunCounter", , False
End If
End Sub

--

HTH

Bob Phillips

(remove nothere from the email address if mailing direct)
 
Top