Is there a Time picker?

B

Barry

I've read numerous posts on numerous boards about time formating, none of
which provide a direction to a true time picker.
There are many a date/time picker references. It would seem to be the
answere to many formating questions and would be a life saver to me.

Anyone know of such a bit of code?


Thanks

Barry
 
J

Jacob Skaria

You could build one. In a fresh UserForm place a textbox (TextBox1) and try
pasting the below code ...Use up/down arrows to adjust the time


Private Sub UserForm_Activate()
Me.TextBox1 = Format(Now, "hh:mm")
End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
'Date and Time Picker Use down/up arrow to change date/time.
Dim intPos As Integer, strType As String
If KeyCode = 38 Or KeyCode = 40 Then
intPos = Me.TextBox1.SelStart
strType = Application.Lookup(intPos, Array(0, 3), Array("h", "n"))
Me.TextBox1 = Format(DateAdd(strType, (39 - KeyCode), TextBox1), "hh:mm")
KeyCode = 0
Me.TextBox1.SelStart = intPos
End If
End Sub



'For Date and Time picker

Private Sub UserForm_Activate()
Me.TextBox1 = Format(Now, "dd-mmm-yyyy hh:mm")
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal
Shift As Integer)
'Date and Time Picker Use down/up arrow to change date/time.
Dim intPos As Integer, strType As String
If KeyCode = 38 Or KeyCode = 40 Then
intPos = Me.TextBox1.SelStart
strType = Application.Lookup(intPos, Array(0, 3, 7, 12, 15), _
Array("d", "m", "yyyy", "h", "n"))
Me.TextBox1 = Format(DateAdd(strType, (39 - KeyCode), _
TextBox1), "dd-mmm-yyyy hh:mm")
KeyCode = 0
Me.TextBox1.SelStart = intPos
End If
End Sub
 
B

Barry

Jacob Skaria,

Using the below code you posted, I have been able to achieve a portion of
the job.
I am somewhat confused as to how to get the selected time from the user form
to the cell selected on the sheet.
As you may have guessed I'm a beginner here so be kind, I do want to learn.

You could build one. In a fresh UserForm place a textbox (TextBox1) and try
pasting the below code ...Use up/down arrows to adjust the time


Private Sub UserForm_Activate()
Me.TextBox1 = Format(Now, "hh:mm")
End Sub

Private Sub TextBox1_KeyDown(ByVal KeyCode As
MSForms.ReturnInteger, ByVal Shift As Integer)
'Date and Time Picker Use down/up arrow to change
date/time.
Dim intPos As Integer, strType As String

If KeyCode = 38 Or KeyCode = 40 Then
intPos = Me.TextBox1.SelStart
strType = Application.Lookup(intPos, Array(0, 3),
Array("h", "n"))
Me.TextBox1 = Format(DateAdd(strType, (39 -
KeyCode), TextBox1), "hh:mm")
KeyCode = 0
Me.TextBox1.SelStart = intPos
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top