Userform textbox to accept only time format.

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Hi,

HOw can I make userform1. textbox1 & textbox2 to accept only time format in hh:mm
then I want textbox3.value = textbox2.value -textbox1.value in time format.
keeps getting error
Code:
Private Sub TextBox3_Enter()
TextBox3.Value = TextBox2.Value - TextBox1.Value
End sub
Thanks
Pedie;)
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Still not working...hope someone can advice on what i must do here....:)
Code:
Private Sub CommandButton1_Click()
UserForm2.TextBox1.Value = Format(Time, "hh:mm:ss AM/PM")
End Sub
 
Private Sub CommandButton2_Click()
UserForm2.TextBox2.Value = Format(Time, "hh:mm:ss AM/PM")
UserForm2.TextBox3.Value = Format(TextBox2.Value - TextBox2.Value, "hh:mm:ss am/pm")
End Sub
 
Upvote 0
Hi Pedie

Spotted this last night, but it was getting late, does this work,

<font face=Courier New><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton1_Click()<br>UserForm2.TextBox1.Value = Format(TextBox1.Value, "hh:mm:ss AM/PM")<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br> <br><SPAN style="color:#00007F">Private</SPAN> <SPAN style="color:#00007F">Sub</SPAN> CommandButton2_Click()<br>UserForm2.TextBox2.Value = Format(TextBox2.Value, "hh:mm:ss AM/PM")<br>mytime1 = TimeValue(UserForm2.TextBox1.Value)<br>mytime2 = TimeValue(TextBox2.Value)<br>mytime3 = mytime2 - mytime1<br>UserForm2.TextBox3.Value = Format(mytime3, "hh:mm")<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Upvote 0
Hi Brian, I thought no one was answering on this so did check back today untill now...:)
Thanks alot for looking into this. I thought you're not around this days...("Didn't see you here so..")
Anyways..when i click on the first button nothing happened. but when i clicked on CommandButton2 it gave runtime error 13' type mismatch

Thanks again
Pedie
 
Upvote 0
Pedie,

What did you enter into Textbox1, and Textbox2.
When I enter 8:00 into Textbox1, and press button one the time is formatted as 08:00:00 AM.
Then if I enter 2:45 pm, or 14:45, into Textbox2 and press button two the time is formatted as 02:45:00 PM.
And Textbox3, displays 06:45, is this not what you wanted. :)
 
Upvote 0
Sorry, Brian, i didnt know that it works that way...:biggrin:
I was clicking on command button without wrting anything on textbox and waiting if the click would give any result....


Thanks again so much!

Pedie
 
Upvote 0

Forum statistics

Threads
1,215,389
Messages
6,124,665
Members
449,178
Latest member
Emilou

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