Advertisement
| 10.08.2008 at 12:24PM PDT, ID: 23798715 | Points: 500 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: |
Public Sub FifteenMinuteIndicatorRoutine()
Dim CurrentDate As Date
Dim Sum As Long
Dim TotalTime As Date
Dim Row As Range
Dim TargetRow As Long
Dim FirstTime As Boolean
Application.ScreenUpdating = False
Application.DisplayAlerts = False
ActiveSheet.[C1].Value = ActiveSheet.[a1].Value
CurrentDate = ActiveSheet.[A2]
CurrentDate = CDbl(Round((CurrentDate + TimeSerial(0, 14, 59)) * 24 * 4)) / 24 / 4
TargetRow = 2
For Each Row In ActiveSheet.UsedRange.Rows
If IsDate(Row.Cells(1, 1)) Then
If Row.Cells(1, 1) <= CurrentDate Then
If Row.Cells(1, 2) = 1 Then
Sum = 1
Else
If Row.Cells(0, 2) = 1 Then TotalTime = TotalTime + Row.Cells(1, 1) - Application.Max(Row.Cells(0, 1), CurrentDate - TimeSerial(0, 15, 0))
End If
Else
FirstTime = True
Do
ActiveSheet.Cells(TargetRow, 3) = CurrentDate
ActiveSheet.Cells(TargetRow, 3).NumberFormat = "M/D/YYYY HH:MM"
ActiveSheet.Cells(TargetRow, 4) = Sum
ActiveSheet.Cells(TargetRow, 4).NumberFormat = "0"
If Row.Cells(1, 2) = 0 And FirstTime Then
TotalTime = TotalTime + CurrentDate - Application.Max(Row.Cells(0, 1), CurrentDate - TimeSerial(0, 15, 0))
FirstTime = False
End If
ActiveSheet.Cells(TargetRow, 5) = TotalTime / TimeSerial(0, 15, 0)
ActiveSheet.Cells(TargetRow, 5).NumberFormat = "0.000"
Sum = Row.Cells(1, 2)
If Row.Row = 10000 Then Stop
CurrentDate = CurrentDate + TimeSerial(0, 15, 0)
CurrentDate = Round(CurrentDate * 24 * 60 * 60) / 24 / 60 / 60
If Row.Cells(1, 2) = 0 Then
TotalTime = Application.Min(Row.Cells(1, 1), CurrentDate) - (CurrentDate - TimeSerial(0, 15, 0))
Else
TotalTime = 0
End If
TargetRow = TargetRow + 1
Loop Until CurrentDate >= Row.Cells(1, 1)
End If
End If
Next Row
Range("D2").Select
ActiveCell.FormulaR1C1 = _
"=IF(R[1]C[-1]<>"""",SUMPRODUCT((R2C[-3]:R10000C[-3]>=RC[-1]-1/96)*(R2C[-3]:R10000C[-3]<RC[-1])*R2C[-2]:R10000C[-2]),"""")"
Selection.AutoFill Destination:=Range("D2:D10000"), Type:=xlFillDefault
Application.ScreenUpdating = True
End Sub
|
Advertisement