Problem,
I am trying to create an application that records work time. So a user would record his start work time, and after the completion of the job, Record the End work time. I am having problems with the code that determines that hours needed for the job.
So in the sample below, the code determines the last imput Start date and Start Time, and then Deduts that from the current Date and time.
However I cant get the hours to come out right. If the project is too long, the code doesn't work right?
help??
Dim Formtimetwo As Date Time1 = Now() Timeround = Round(Time1 * 24 * 4) / 24 / 4 Formtimetwo = Format(Timeround, "m/d/yyyy h:mm:ss AM/PM") 'Current time Formated 'Below are what was previously recorded Pastdate = Ws2.Cells(Ws2.Rows.Count, 3).End(xlUp).Offset(0, 0).Value Pasttime = Ws2.Cells(Ws2.Rows.Count, 4).End(xlUp).Offset(0, 0).Value PastDateandTime = Pastdate + Pasttime Hours123 = Formtimetwo - PastDateandTime If Hours123 < "1" then TotalHours = Format(Hours123, "h:mm") Else TotalHours = Format(Hours123, "[h]:mm:ss") End if Range("Admin!E2").value = TotalHours
Hi Crebsington
Dont really follow what your doing but
have a look at this example form the VBA help on DateDiff
Dim TheDate As Date ' Declare variables. Dim Msg TheDate = InputBox("Enter a date") Msg = "Days from today: " & DateDiff("d", Now, TheDate) MsgBox Msg
regards pike
If the solution helped please donate here to the RSPCA
Sites worth visiting;
J&R Solutions - royUK
AJP Excel Information - Andy Pope
Spreadsheet Toolbox
VBA for smarties - snb
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks