Hello,
The goal of this code is to take 4 time values, timeon, timeoff, peakstart, and peakend. These are time formatted cells in excell that will vary in actual time.
Then, I have it count how many minutes of the appliance is on during peak hours.
The end result I am looking for is for it to output the peak hours in the cell the function is in, and the nonpeak hours in the cell one column to the right, in number form, not time.
I keep getting a #Value, but cannot figure out why or what I am doing wrong.
Here is the main block of code
Function onpeak(timeon, timeoff)
Dim xtime As Double
Dim min As Date
Dim peakhrs As Date
Dim offpeakhrs As Date
Dim peakend As Double
Dim peakstart As Double
xtime = timeon
min = Time(0, 0, 0)
peakhrs = Time(0, 0, 0)
offpeakhrs = Time(0, 0, 0)
If peakstart <= timeon And peakend > timeon Then
Do While xtime < pke And xtime <> timeoff
xtime = xtime + Time(0, 1, 0)
min = min + Time(0, 1, 0)
Loop
peakhrs = min * 24
nonpeakhrs = Tdif(timeon, timeoff) - (peakhrs)
Else
peakhrs = Time(0, 0, 0) * 24
nonpeakhrs = Tdif(timeon, timeoff)
End If
ActiveCell.Value = peakhrs
ActiveCell.Offset(0, 1).Value = nonpeakhrs
End Function
Here is a function I call in that code.
Function Tdif(time1, time2)
If time1 > time2 Then
Tdif = (time2 - time1 + 1) * 24
Else
Tdif = (time2 - time1) * 24
End If
End Function
If you could help me out, that would be great.
Mike
Bookmarks