Hi,
I'm trying to build a userform to calculate times to work out employee timesheet on how many hrs they have done e.g. Start time 9:00am to 5:00pm = 8hrs but I'm unable to get this as it's not calculating the two "times"
Is anyone able to help me with my VBA?
Full code of my userform
I'm trying to build a userform to calculate times to work out employee timesheet on how many hrs they have done e.g. Start time 9:00am to 5:00pm = 8hrs but I'm unable to get this as it's not calculating the two "times"
Is anyone able to help me with my VBA?
VBA Code:
TextBox3 = Int((Val(TextBox2.Value) - Val(TextBox1.Value)) * 24)
Full code of my userform
Code:
Private Sub cmdcalculate_Click()
TextBox3 = Int((Val(TextBox2.Value) - Val(TextBox1.Value)) * 24)
End Sub
Private Sub cmdclearinfo_Click()
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
End Sub
Private Sub cmdexist_Click()
Unload UserForm1
End Sub
Private Sub TextBox1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not Me.TextBox1 Like "??:??" Then
MsgBox "Please use format 'hh:mm'"
Cancel = True
Exit Sub
Else
End If
myVar = Application.WorksheetFunction.Text(Me.TextBox1, "hh:mm am/pm")
Me.TextBox1 = myVar
End Sub
Private Sub TextBox2_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)
If Not Me.TextBox2 Like "??:??" Then
MsgBox "Please use format 'hh:mm'"
Cancel = True
Exit Sub
Else
End If
myVar = Application.WorksheetFunction.Text(Me.TextBox2, "hh:mm am/pm")
Me.TextBox2 = myVar
End Sub