View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
James Ravenswood James Ravenswood is offline
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