Rolling Average

machroz

New Member
Joined
Mar 27, 2004
Messages
3
Hello, I'm logging temperature data into an excel spread sheet every two(2) minutes for the EPA. The EPA requires a 3 hour rolling average. I must maintain the log for 30 days. For a 30 day month that equals 21,600 samples. I need a rolling average to display the average of the last 3 hours everytime it updates. Could someone please help me out.

Thank you,
Mike
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi, Hello, and Welcome to MrExcel --

Are we going to have all these samples in one column? How are they input?
 
Upvote 0
Hello Just_Jon, thank you for the quick response. The samples will be all in the same column. The info is a .dbf file which is logged in RSView32 software. When the month of logging is complete the .dbf file is viewed through excel. The temperature will be in D2 through D21,601. I would need the rolling average calculated and displayed in E2 through E21,601. The site Excel experts told me it can't be done but I don't believe that. I have a little VB training but I've never used it in Excel. I appreciate any help you could give.

Thanks,
MIke :biggrin:
 
Upvote 0
So, each row will have an average on it, even if it is the of the first few minutes/hours.

Will the date and time also be present? If so, where.

When you say every 2 minutes, will this be exactly? And a 3-hr average, if you've temps for all day will the 3PM average include or exclude noon?
 
Upvote 0
This untested code should generate a simple average based on the latest data up to a max of 90 last temps [every 2 minutes = 30/hr x 3 hrs = 90 observations].

Please test it on a 100 point sample to make sure it works.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> TakinMyTempWithoutAThermometer()

<SPAN style="color:#00007F">Dim</SPAN> LastRow <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>
LastRow = [D65536].End(xlUp).Row
<SPAN style="color:#00007F">For</SPAN> i = 2 <SPAN style="color:#00007F">To</SPAN> LastRow
    <SPAN style="color:#00007F">If</SPAN> i <= 91 <SPAN style="color:#00007F">Then</SPAN>
        Cells(i, 5) = Application.WorksheetFunction.Sum(Range("D2:D" & i))
    <SPAN style="color:#00007F">Else</SPAN>
        Cells(i, 5) = Application.WorksheetFunction.Sum(Range("D" & i - 89 & ":D" & i))
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    Cells(i, 5) = Cells(i, 5) / Application.WorksheetFunction.Min(90, i - 1)
<SPAN style="color:#00007F">Next</SPAN> i

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

</FONT>
 
Upvote 0
BTW, the above can be translated into a worksheet change event macro, which can be set to fire any time there is a change to column D, thereby deleting the need to explicitly run the macro.
 
Upvote 0
Hello Just_Jon, your code work with very well for what I needed. My boss changed the format of the sheet on me but I was able to wiggle things around and use your code. Thanks for your help.

Thanks,
Mike :pray:
 
Upvote 0

Forum statistics

Threads
1,215,032
Messages
6,122,770
Members
449,095
Latest member
m_smith_solihull

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