Time Picker in excel user form

shreyas17

New Member
Joined
Jul 22, 2021
Messages
17
Office Version
  1. 2016
Platform
  1. Windows
Hi Everyone,

I am trying to put a time picker in my user form and I have created a text box and 2 spin buttons for hours and minutes.

Can anyone help me with how can I proceed with code and how to incorporate the two buttons into the text box.

1628237121826.png

Kind Regards,
SS
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
These controls look as though they are on a worksheet and not a userform?
The following code works for me. I have assumed a 24hr time picker which goes as low as 00:00 (midnight) and as high as 23:59 (11:59pm).

VBA Code:
Private Sub SpinButton1_Change()
    
    If SpinButton1.Value = -1 Then SpinButton1.Value = 0
    If SpinButton1.Value = 24 Then SpinButton1.Value = 23
    
    TextBox1.Text = Format(SpinButton1.Value, "00") & ":" & Format(SpinButton2.Value, "00")
End Sub

Private Sub SpinButton2_Change()
    If SpinButton2.Value = -1 Then SpinButton2.Value = 0
    If SpinButton2.Value = 60 Then SpinButton2.Value = 59

    TextBox1.Text = Format(SpinButton1.Value, "00") & ":" & Format(SpinButton2.Value, "00")
End Sub

Note that this code does not permit the user to manually enter in a time.
 
Upvote 0
Solution

Forum statistics

Threads
1,216,101
Messages
6,128,843
Members
449,471
Latest member
lachbee

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