Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Validate text box entry on user form
I have text box on a user form, the user is to enter time taken to do a
certain task in it. I want the time to be entered in time format - h:mm The number of hours can be 0 to 100 In the OK click code I want to check if the entry is correct, that is, 3rd from the right is a':' and the last two digits are less than 60 Examples: 9:45 OK 9:75 Not OK The entry is then put into a cell within the file. Thanks in advance. Gareth |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Validate text box entry on user form
Gareth wrote:
I have text box on a user form, the user is to enter time taken to do a certain task in it. I want the time to be entered in time format - h:mm The number of hours can be 0 to 100 In the OK click code I want to check if the entry is correct, that is, 3rd from the right is a':' and the last two digits are less than 60 Examples: 9:45 OK 9:75 Not OK The entry is then put into a cell within the file. Private Sub CommandButton1_Click() Dim ok As Boolean, arr As Variant ok = False If TextBox1 Like "*#:##" Then arr = Split(TextBox1, ":") If IsNumeric(arr(0)) Then If arr(0) <= 100 And arr(1) < 60 Then ok = True End If End If End If If ok Then ActiveSheet.Cells(1, 1).Formula = TextBox1 End Sub -- Steve Garman |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Validate text box entry on user form
Gareth,
Private Sub TextBox1_AfterUpdate() 'Is time formatted correctly? If Mid(TextBox1.Text, Len(TextBox1.Text) - 2, 1) = ":" And _ Right(TextBox1.Text, 2) < 60 Then Sheets("sheet1").Range("Z99") = TextBox1.Text Else 'Not formatted correctly, so tell user. MsgBox "Time MUST contain a colon ':' and be in Hours and Minutes", "Error" End If End Sub Private Sub CommandButton1_Click() 'Check that time has been saved. 'if it hasn't, then user has ignored message box! 'don't exit form until time entered correctly If Sheets("sheet1").Range("Z99") = TextBox1.Text Then Unload UserForm1 End Sub "Gareth" wrote in message ... I have text box on a user form, the user is to enter time taken to do a certain task in it. I want the time to be entered in time format - h:mm The number of hours can be 0 to 100 In the OK click code I want to check if the entry is correct, that is, 3rd from the right is a':' and the last two digits are less than 60 Examples: 9:45 OK 9:75 Not OK The entry is then put into a cell within the file. Thanks in advance. Gareth |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Validate date entry in a text box. | Excel Discussion (Misc queries) | |||
User Form: Cannot Update Text Box | Excel Discussion (Misc queries) | |||
Filter Excel Pivot, based on user entry form | Excel Discussion (Misc queries) | |||
Auto email - With every new entry on my user form | Excel Discussion (Misc queries) | |||
Data Entry Alert in User Form | Excel Discussion (Misc queries) |