As part of this I need to round the time to nearest 0,15,30,45 interval. I found a very good script Here : https://msdn.microsoft.com/en-us/lib...(v=vs.60).aspx
My code looks like this:
The highlighted section above is giving me an error.
I think it may be due to the format of my dhRoundTime(timestarted, 15) being a Variable instead of a dhRoundTime(#12:32:15#, 15)
This is the content of the cell for timestarted "7/9/2015 8:51:42 AM"
Thanks for looking
My code looks like this:
Code:
timestarted = DateValue(Sheet2.Cells(2, 9))
Private Sub CommandButton1_Click()
Dim Ndate, timestarted, timeworked, RTime, WTime As Date
Ndate = NOW
If Ndate > timestarted Then
'length of time worked on a project
timeworked = Ndate - timestarted
'round start up time to nearest 15 to find it on time sheet and mark it
[B][COLOR=#ff0000]RTime = dhRoundTime(timestarted, 15)[/COLOR][/B]
'round time worked to nearest 15 to find it on time sheet and mark it
WTime = dhRoundTime(timeworked, 15)
End If
End Sub
Function dhRoundTime(dtmTime As Date, intInterval As Integer) As Date
' Round the time value in varTime to the nearest minute
' interval in intInterval
Dim intTime As Integer
Dim sglTime As Single
Dim intHour As Integer
Dim intMinute As Integer
Dim lngdate As Long
' Get the date portion of the date/time value
lngdate = DateValue(dtmTime)
' Get the time portion as a number like 11.5 for 11:30.
sglTime = TimeValue(dtmTime) * 24
' Get the hour and store it away. Int truncates,
' CInt rounds, so use Int.
intHour = Int(sglTime)
' Get the number of minutes, and then round to the nearest
' occurrence of the interval specified.
intMinute = CInt((sglTime - intHour) * 60)
intMinute = CInt(intMinute / intInterval) * intInterval
' Build back up the original date/time value,
' rounded to the nearest interval.
'changed this line to return only the rounded time needed
dhRoundTime = CDate((intHour + intMinute / 60) / 24)
'orginal line below
'dhRoundTime = CDate(lngdate + ((intHour + intMinute / 60) / 24))
End Function
The highlighted section above is giving me an error.
I think it may be due to the format of my dhRoundTime(timestarted, 15) being a Variable instead of a dhRoundTime(#12:32:15#, 15)
This is the content of the cell for timestarted "7/9/2015 8:51:42 AM"
Thanks for looking