ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Is there a Time picker? (https://www.excelbanter.com/excel-discussion-misc-queries/256768-there-time-picker.html)

Barry

Is there a Time picker?
 
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



Jacob Skaria

Is there a Time picker?
 
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

--
Jacob


"Barry" wrote:

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


.


Barry

Is there a Time picker?
 
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




All times are GMT +1. The time now is 06:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com