PDA

View Full Version : VBA code to subtract the time diferences in the userform.



Master_Viper
01-19-2017, 09:50 AM
hello all,

I would like to ask help. I have two time picker in the userform and called it time start and end time.
I want to subtract the differences of the two time then the value will automatically paste in the worksheet under the column "F".
When the user click the button "Add new entry".

Thanks in advance!

Paul_Hossler
01-19-2017, 10:28 AM
Doesn't this work? The Custom Number Format you had was h:mm which works, unless you wanted h:mm:ss





'ActiveCell.Offset(0, 5).Value = Me.txtTotalDown.Text 'set col F

ActiveCell.Offset(0, 5).Value = ActiveCell.Offset(0, 4).Value - ActiveCell.Offset(0, 3).Value

Master_Viper
01-19-2017, 02:21 PM
Thanks, Paul.

Master_Viper
01-24-2017, 10:00 AM
Hi Paul,

Why is it that when I change the Start Time and End Time selection from date time picker to combobox the total time I've got is 9 digit instead of 3 digit only when it will transfer the

data into active cell. Please find attached file.

Master_Viper

Master_Viper
01-25-2017, 08:28 AM
Hello Guys,

Anyone can help to configure. VBA code to subtract the time differences in the userform using combobox instead of datetimepicker.

SamT
01-25-2017, 11:07 AM
UserForm Controls only contain Strings.
If the Time in a ComboBox is like "hh:mm" You should Concatenate a Date and the CmboBx Value then use DataDiff


TimeDifferenceInMinutes = DateDiff("n", Date & Cbx1, Date & Cbx2)

Since that can return a false value if run at 11:59:59.999 PM


TimeDifferenceInMinutes = DateDiff("n", "1/1/11" & Cbx1, "1/1/11 & Cbx2) 'Any Date String will work