User Form

Sandy Radjenovic

Board Regular
Joined
Nov 4, 2003
Messages
76
I have a User Form where the following is entered:

Start Date & Start Time
End Date & End Time

I would like to include an additional calculated field in the form which will display the variance in time between the two.

How would I insert this calculated field into the form?

Any insight would be great!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
you can use the change event on your start_time and end_time fields to call a function that calculates the difference and places it into your elapsed time field.

Private Sub end_time_Change()
If start_time <> vbNullString Then
elapsed_time = getDiff
End If
End Sub

Function getDiff() As String
' This will give you the hours difference
diff = DateDiff("h", CDate(start_time), CDate(end_time))

getDiff = diff & " Hours"
End Function
 
Upvote 0

Forum statistics

Threads
1,221,687
Messages
6,161,287
Members
451,695
Latest member
Doug Mize 1024

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top