Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Userform addition question

I have a user form in which I enter a start time (Textbox1) and an end time
in (Textbox2).

What I need to have happen on the Userform is for Textbox3 to be filled in
with the total time worked. The start and end times are entered as times
(hh:mm) but the result in Textbox3 must be in decimal format (8.3).


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Userform addition question

Hi Patrick,

TextBox3.Text = Format((CDate(TextBox2.Text) - _
CDate(TextBox1.Text)) * 24, _
"##0.0")

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Patrick Simonds" wrote in message
...
I have a user form in which I enter a start time (Textbox1) and an end

time
in (Textbox2).

What I need to have happen on the Userform is for Textbox3 to be filled in
with the total time worked. The start and end times are entered as times
(hh:mm) but the result in Textbox3 must be in decimal format (8.3).




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Userform addition question

Just some amplification. The code below is what I was using when we entered
time in the decimal format, but I have not been successful in converting it
to what is required now.



Sub TotalHours2()

Dim bTest1 As Boolean
Dim bTest2 As Boolean
Dim bTest3 As Boolean
Dim dblElapsed

With UserForm1

If IsNumeric(.TextBox4.Text) And _
IsNumeric(.TextBox5.Text) And _
IsNumeric(.ComboBox12.Text) Then

dblElapsed = (CDbl(.TextBox5.Text) - CDbl(.TextBox4.Text) -
CDbl(.ComboBox12.Text))

.TextBox6.Value = Format(dblElapsed, "#0.00")

If .ComboBox2.Value = "" Then GoTo EnterCode
GoTo EndMacro

EnterCode:

.ComboBox2.Value = "01"

Else

'MsgBox "There is an invalid time"

End If

GoTo EndMacro

ClearBox:

UserForm1.TextBox4.Value = Format("", "")
UserForm1.TextBox5.Value = Format("", "")
UserForm1.TextBox6.Value = Format("", "")

EndMacro:

End With

End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Userform addition question


Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If InStr(TextBox2.Text, ":") And _
Trim(TextBox2.Text) < "" Then
If InStr(TextBox1.Text, ":") And _
Trim(TextBox1.Text) < "" Then
TextBox3.Text = Format((CDate(TextBox2.Text) _
- CDate(TextBox1.Text)) * 24, "#.0")
End If
End If
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If InStr(TextBox1.Text, ":") And _
Trim(TextBox1.Text) < "" Then
If InStr(TextBox2.Text, ":") And _
Trim(TextBox2.Text) < "" Then
TextBox3.Text = Format((CDate(TextBox2.Text) _
- CDate(TextBox1.Text)) * 24, "#.0")
End If
End If
End Sub


You can add other checks to make sure the end time is greater than the start
time or to calculate over midnight.

--
Regards,
Tom Ogilvy


"Patrick Simonds" wrote in message
...
I have a user form in which I enter a start time (Textbox1) and an end

time
in (Textbox2).

What I need to have happen on the Userform is for Textbox3 to be filled in
with the total time worked. The start and end times are entered as times
(hh:mm) but the result in Textbox3 must be in decimal format (8.3).




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
column addition question D Excel Worksheet Functions 1 February 19th 06 11:50 PM
Same Question with one more addition of a dash to count Mahendra Excel Discussion (Misc queries) 0 August 4th 05 11:37 PM
userform question keyur Excel Programming 2 April 14th 04 04:49 PM
Userform question John Holland Excel Programming 2 October 28th 03 05:49 PM
In addition to previous question, if opening an Excel file in NON-read-only mode, would the macros on the worksheets work as well? Greener Excel Programming 2 October 9th 03 03:40 AM


All times are GMT +1. The time now is 12:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"