KeyDown in TextBox to increment Number

S

Slim Slender

This procedure for a textbox increments time by 15 minutes. I want to
change it so that
the content is a simple number in format "#0.00" and the KeyDown
increments the number by 0.25

Private Sub txtStartTime_KeyDown(ByVal KeyCode _
As MSForms.ReturnInteger, _
ByVal Shift As Integer)

Dim sDate As String
Dim v As Integer
dte As Date

Select Case KeyCode
Case 37 ' Left
v = -1
Case 39 ' Right
v = 1
Case Else
v = 0
End Select
sDate = txtStartTime.Text

If IsDate(sDate) And v <> 0 Then
dte = CDate(sDate)
dte = dte + v * TimeValue("00:15")
txtStartTime = Format(dte, "h:mm AM/PM")
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

Similar Threads


Top