Hi,
I've created a userform where people capture information and have to time the process for the work that they are doing. The information is then transferred to the worksheet and the data moves down the next row. using the following code:
I'm trying to use the timer option to calculate the time taken to do a process. I've used an the NOW() function to enter the different times which gets added clicking start, pause, continue and stop buttons.
The problem is that when it does the calculation it returns the time "as in a actual clock time" - if that makes sense - instead of the time difference in hours, minutes or seconds taken from when the start button and stop buttons were click, also if the pause and continue buttons where clicked. is there a way that i can do this calculation in VBA and then export this to the worksheet.
I don't know where I'm going wrong, please help.
I've created a userform where people capture information and have to time the process for the work that they are doing. The information is then transferred to the worksheet and the data moves down the next row. using the following code:
Code:
Range("A10:V10").SelectRows(10).Insert shift:=xlShiftDown
firstrow = ActiveCell.Row
Cells(firstrow + 1, 1).Value = UserTextBox.Text
Cells(firstrow + 1, 2).Value = Company.Text
Cells(firstrow + 1, 3).Value = CurrentDate.Text
Cells(firstrow + 1, 4).Value = DateReceived.Text
Cells(firstrow + 1, 5).Value = TimeReceived.Text
Cells(firstrow + 1, 6).Value = DateSignOff.Text
Cells(firstrow + 1, 7).Value = Requestor.Text
Cells(firstrow + 1, 8).Value = BeginTimeBox.Text
Cells(firstrow + 1, 9).Value = EndTime
Cells(firstrow + 1, 10).Value = WorkCategory.Text
Cells(firstrow + 1, 11).Value = ActivityTextBox.Text
Cells(firstrow + 1, 12).Value = InHouseBox.Text
Cells(firstrow + 1, 13).Value = Path.Text
Cells(firstrow + 1, 14).Value = Skill.Text
Cells(firstrow + 1, 15).Value = Validity.Text
Cells(firstrow + 1, 16).Value = CommentBox.Text
Cells(firstrow + 1, 17).Value = ManualTime.Text
Cells(firstrow + 1, 18).Value = PausedTimeBox.Text
Cells(firstrow + 1, 19).Value = ContinuedTimeBox.Text
Cells(firstrow + 1, 20).Value = TimeSignOff.Text
Cells(firstrow + 1, 21).Value = ""
Cells(firstrow + 1, 22).Value = Duration
I'm trying to use the timer option to calculate the time taken to do a process. I've used an the NOW() function to enter the different times which gets added clicking start, pause, continue and stop buttons.
Code:
Private Sub StartButton_Click()'Inserts the start time and date
'Start time function
Dim BeginTime As Date
BeginTime = Format(Now(), "hh:mm:ss")
StatsCapture.BeginTimeBox.Value = BeginTime
End Sub
Private Sub PauseButton_Click()
'Inserts the pause time
'Pause time function
'Checks if timer has been started
If StatsCapture.BeginTimeBox.Value = "" Then
MsgBox "Timer has not been started!"
Exit Sub
End If
Dim PausedTime As Date
PausedTime = Format(Now(), "hh:mm:ss")
StatsCapture.PausedTimeBox.Value = PausedTime
End Sub
Private Sub ContinueButton_Click()
'Inserts the pause time
'Pause time function
'Checks if timer has been started
If StatsCapture.BeginTimeBox.Value = "" Then
MsgBox "Timer has not been started!"
Exit Sub
End If
'Checks if timer has been paused
If StatsCapture.PausedTimeBox.Value = "" Then
MsgBox "Timer is not paused!"
Exit Sub
End If
Dim ContinuedTime As Date
ContinuedTime = Format(Now(), "hh:mm:ss")
StatsCapture.ContinuedTimeBox.Value = ContinuedTime
End Sub
'Returns end time when button is pressed
Dim EndTime As Date
EndTime = Format(Now(), "hh:mm:ss")
'Calculates the time taken for the process
Dim Duration As Double
Duration = EndTime + PauseTime - StartTime - ContinueTime
The problem is that when it does the calculation it returns the time "as in a actual clock time" - if that makes sense - instead of the time difference in hours, minutes or seconds taken from when the start button and stop buttons were click, also if the pause and continue buttons where clicked. is there a way that i can do this calculation in VBA and then export this to the worksheet.
I don't know where I'm going wrong, please help.