A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Programming
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Time averaging raw data



 
 
Thread Tools Display Modes
  #1  
Old May 28th 12, 09:46 AM posted to microsoft.public.excel.programming
Chris J Denver
external usenet poster
 
Posts: 7
Default Time averaging raw data

Hi newsgroup,

I have got a spreadsheet with 10 minute data as follows:

Timestamp;Value
01/01/12 00:00; 12
01/01/12 00:10; 10
01/01/12 00:20; 11
....

I would like to average this data into half hourly as follows

Timestamp;Value
01/01/12 00:30; 11

and am trying to write a macro to do this. Now this would be easy if
there were always three 10min data points to average, but the problem
is that often there is data missing, so instead there could be only 2,
1, or no 10min data points within one 30min timeframe. I would need
the macro to read the timestamp (MS Office format) and based on this
write averages for each 30min timeframe. And this is what I can't sort
out how to do...

Any help would be greatly appreciated!

Many thanks,

Chris
Ads
  #2  
Old May 28th 12, 01:48 PM posted to microsoft.public.excel.programming
James Ravenswood
external usenet poster
 
Posts: 143
Default Time averaging raw data

Say the active cell is on some timevalue. If the time difference between the first and third time is less than or equal to 30 minutes, average three values and exit. If the time difference between the first and second time is less than or equal to 30 minutes, then average the first and second values and exit. For example:


Sub TimeAverage()
Dim r As Range
Set r = ActiveCell

t1 = r.Value
t2 = r.Offset(1, 0).Value
t3 = r.Offset(2, 0).Value

v1 = r.Offset(0, 1).Value
v2 = r.Offset(1, 1).Value
v3 = r.Offset(2, 1).Value

If t3 - t1 <= 0.020833333 Then
MsgBox (v1 + v2 + v3) / 3
Exit Sub
End If

If t2 - t1 <= 0.020833333 Then
MsgBox (v1 + v2) / 2
Exit Sub
End If

MsgBox v1
End Sub

  #3  
Old May 28th 12, 03:15 PM posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Time averaging raw data

Hi James,

> Say the active cell is on some timevalue. If the time difference between the first and third time is less than or equal to 30 minutes, average three values and exit. If the time difference between the first and second time is less than or equal to 30 minutes, then average the first and second values and exit.


Perfect, many thanks. I've now put that in a loop and it works fine!

Best,

Chris
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Averaging Time Exec. Lt. GMP Excel Programming 8 January 7th 10 02:24 PM
Averaging Time BostonBoy Excel Worksheet Functions 14 August 26th 08 12:07 AM
Averaging Time BostonBoy Excel Worksheet Functions 1 August 23rd 08 12:38 AM
Averaging Time BostonBoy Excel Worksheet Functions 4 August 22nd 08 11:30 PM
Averaging set of data based on the time voyager1 Excel Worksheet Functions 2 March 30th 08 11:04 PM


All times are GMT +1. The time now is 10:32 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Copyright ©2004-2013 ExcelBanter.
The comments are property of their posters.