E
Erik
When my spreadsheet starts a userform comes up up with a recommendation for
"time in". I can change the time, but I do not want to be able to delete or
change the colon. Actually I do not want to be able to delete the recommended
time either, just be able to change it: I do not want my textbox to be empty.
How can I do this?
Here's the code:
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
Dim TimeOut As String
Dim TimeNow As Date
Dim TimeNowMinus As String
Dim Time as String
TimeNow = WorksheetFunction.Text(Now(), "hh:mm")
Time = "14:50"
TimeNowMinus = Format(Now - Date - TimeValue("00:03:00"), "hh:mm")
Me.StartUpPosition = 0
Me.Top = 186
Me.Left = 382
Select Case True
Case TimeNow < Time
OptionButton1.Value = True
TextBox1.Text = TimeNowMinus
Case Else
OptionButton2.Value = True
TextBox1.Text = "16:00"
End Select
With Me.TextBox1
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
Application.ScreenUpdating = True
End Sub
"time in". I can change the time, but I do not want to be able to delete or
change the colon. Actually I do not want to be able to delete the recommended
time either, just be able to change it: I do not want my textbox to be empty.
How can I do this?
Here's the code:
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
Dim TimeOut As String
Dim TimeNow As Date
Dim TimeNowMinus As String
Dim Time as String
TimeNow = WorksheetFunction.Text(Now(), "hh:mm")
Time = "14:50"
TimeNowMinus = Format(Now - Date - TimeValue("00:03:00"), "hh:mm")
Me.StartUpPosition = 0
Me.Top = 186
Me.Left = 382
Select Case True
Case TimeNow < Time
OptionButton1.Value = True
TextBox1.Text = TimeNowMinus
Case Else
OptionButton2.Value = True
TextBox1.Text = "16:00"
End Select
With Me.TextBox1
.SelStart = 0
.SelLength = Len(.Text)
.SetFocus
End With
Application.ScreenUpdating = True
End Sub