ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   KeyDown in TextBox to increment Number (https://www.excelbanter.com/excel-programming/439799-keydown-textbox-increment-number.html)

Slim Slender[_2_]

KeyDown in TextBox to increment Number
 

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


All times are GMT +1. The time now is 10:48 AM.

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