Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am looking for something that will catch if the user does not enter a
valid time. For example if they were to enter 0995 instead of 0955. What I need is if they do enter a wrong value that a msgbox would pop up telling them there value was not correct and then reselect the textbox so that the value can be changed. Below is my code as it stands now. Private Sub TextBox11_AfterUpdate() TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox13.Value = (TimeValue(TextBox12.Value) - TimeValue(TextBox11.Value)) * 24 TextBox13.Value = Format(TextBox13.Value, "0.0000") TextBox1.Value = CDbl("0" & TextBox13.Value) + CDbl("0" & TextBox23.Value) + CDbl("0" & TextBox33.Value) + CDbl("0" & TextBox43.Value) + CDbl("0" & TextBox53.Value) + CDbl("0" & TextBox63.Value) + CDbl("0" & TextBox14.Value) + CDbl("0" & TextBox24.Value) + CDbl("0" & TextBox34.Value) + CDbl("0" & TextBox44.Value) + CDbl("0" & TextBox54.Value) + CDbl("0" & TextBox64.Value) TextBox1.Text = Format(TextBox1.Text, "0.0000") End If End If 'Test that to see if hours worked exceeds shift length If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox2 = TextBox4 - TextBox1 End If If TextBox2.Value < 0 Then TextBox2.Value = 0 GoTo Finished End If TextBox2 = TextBox4 - TextBox1 TextBox2.Text = Format(TextBox2.Text, "0.0000") End If Finished: If TextBox12.Value = "" Then TextBox13.Value = "" End If If TextBox11.Value = "" Then TextBox13.Value = "" End If End Sub |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
One way:
Debug.Print IsDate("09:95"), IsDate("09:55") or Debug.Print IsDate(Format("0955","00\:00")) In article , "Patrick C. Simonds" wrote: I am looking for something that will catch if the user does not enter a valid time. For example if they were to enter 0995 instead of 0955. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":",
""), "00\:00"), "hh:mm") First off, you don't need to use the worksheet's Text function to do the above... VB's Format function can do it. TextBox11.Value = Format(Format(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") However, you need to break that line up into two lines in order to test if the input is a valid time... TestDateVariable = Format(Replace(TextBox11.Value, ":", ""), "00\:00") If IsDate(TestDateVariable) Then TextBox11.Value = Format(TestDateVariable, "hh:mm") ' ' Rest of your code goes here ' Else MsgBox "That is not a valid time value!!!" ' ' Not sure what you will want to do next ' End If -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... I am looking for something that will catch if the user does not enter a valid time. For example if they were to enter 0995 instead of 0955. What I need is if they do enter a wrong value that a msgbox would pop up telling them there value was not correct and then reselect the textbox so that the value can be changed. Below is my code as it stands now. Private Sub TextBox11_AfterUpdate() TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox13.Value = (TimeValue(TextBox12.Value) - TimeValue(TextBox11.Value)) * 24 TextBox13.Value = Format(TextBox13.Value, "0.0000") TextBox1.Value = CDbl("0" & TextBox13.Value) + CDbl("0" & TextBox23.Value) + CDbl("0" & TextBox33.Value) + CDbl("0" & TextBox43.Value) + CDbl("0" & TextBox53.Value) + CDbl("0" & TextBox63.Value) + CDbl("0" & TextBox14.Value) + CDbl("0" & TextBox24.Value) + CDbl("0" & TextBox34.Value) + CDbl("0" & TextBox44.Value) + CDbl("0" & TextBox54.Value) + CDbl("0" & TextBox64.Value) TextBox1.Text = Format(TextBox1.Text, "0.0000") End If End If 'Test that to see if hours worked exceeds shift length If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox2 = TextBox4 - TextBox1 End If If TextBox2.Value < 0 Then TextBox2.Value = 0 GoTo Finished End If TextBox2 = TextBox4 - TextBox1 TextBox2.Text = Format(TextBox2.Text, "0.0000") End If Finished: If TextBox12.Value = "" Then TextBox13.Value = "" End If If TextBox11.Value = "" Then TextBox13.Value = "" End If End Sub |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
After the msgbox is dismissed I need TextBox11 to be active.
"Rick Rothstein" wrote in message ... TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") First off, you don't need to use the worksheet's Text function to do the above... VB's Format function can do it. TextBox11.Value = Format(Format(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") However, you need to break that line up into two lines in order to test if the input is a valid time... TestDateVariable = Format(Replace(TextBox11.Value, ":", ""), "00\:00") If IsDate(TestDateVariable) Then TextBox11.Value = Format(TestDateVariable, "hh:mm") ' ' Rest of your code goes here ' Else MsgBox "That is not a valid time value!!!" ' ' Not sure what you will want to do next ' End If -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... I am looking for something that will catch if the user does not enter a valid time. For example if they were to enter 0995 instead of 0955. What I need is if they do enter a wrong value that a msgbox would pop up telling them there value was not correct and then reselect the textbox so that the value can be changed. Below is my code as it stands now. Private Sub TextBox11_AfterUpdate() TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox13.Value = (TimeValue(TextBox12.Value) - TimeValue(TextBox11.Value)) * 24 TextBox13.Value = Format(TextBox13.Value, "0.0000") TextBox1.Value = CDbl("0" & TextBox13.Value) + CDbl("0" & TextBox23.Value) + CDbl("0" & TextBox33.Value) + CDbl("0" & TextBox43.Value) + CDbl("0" & TextBox53.Value) + CDbl("0" & TextBox63.Value) + CDbl("0" & TextBox14.Value) + CDbl("0" & TextBox24.Value) + CDbl("0" & TextBox34.Value) + CDbl("0" & TextBox44.Value) + CDbl("0" & TextBox54.Value) + CDbl("0" & TextBox64.Value) TextBox1.Text = Format(TextBox1.Text, "0.0000") End If End If 'Test that to see if hours worked exceeds shift length If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox2 = TextBox4 - TextBox1 End If If TextBox2.Value < 0 Then TextBox2.Value = 0 GoTo Finished End If TextBox2 = TextBox4 - TextBox1 TextBox2.Text = Format(TextBox2.Text, "0.0000") End If Finished: If TextBox12.Value = "" Then TextBox13.Value = "" End If If TextBox11.Value = "" Then TextBox13.Value = "" End If End Sub |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Try using this to activate the TextBox...
TextBox11.SetFocus -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... After the msgbox is dismissed I need TextBox11 to be active. "Rick Rothstein" wrote in message ... TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") First off, you don't need to use the worksheet's Text function to do the above... VB's Format function can do it. TextBox11.Value = Format(Format(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") However, you need to break that line up into two lines in order to test if the input is a valid time... TestDateVariable = Format(Replace(TextBox11.Value, ":", ""), "00\:00") If IsDate(TestDateVariable) Then TextBox11.Value = Format(TestDateVariable, "hh:mm") ' ' Rest of your code goes here ' Else MsgBox "That is not a valid time value!!!" ' ' Not sure what you will want to do next ' End If -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... I am looking for something that will catch if the user does not enter a valid time. For example if they were to enter 0995 instead of 0955. What I need is if they do enter a wrong value that a msgbox would pop up telling them there value was not correct and then reselect the textbox so that the value can be changed. Below is my code as it stands now. Private Sub TextBox11_AfterUpdate() TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox13.Value = (TimeValue(TextBox12.Value) - TimeValue(TextBox11.Value)) * 24 TextBox13.Value = Format(TextBox13.Value, "0.0000") TextBox1.Value = CDbl("0" & TextBox13.Value) + CDbl("0" & TextBox23.Value) + CDbl("0" & TextBox33.Value) + CDbl("0" & TextBox43.Value) + CDbl("0" & TextBox53.Value) + CDbl("0" & TextBox63.Value) + CDbl("0" & TextBox14.Value) + CDbl("0" & TextBox24.Value) + CDbl("0" & TextBox34.Value) + CDbl("0" & TextBox44.Value) + CDbl("0" & TextBox54.Value) + CDbl("0" & TextBox64.Value) TextBox1.Text = Format(TextBox1.Text, "0.0000") End If End If 'Test that to see if hours worked exceeds shift length If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox2 = TextBox4 - TextBox1 End If If TextBox2.Value < 0 Then TextBox2.Value = 0 GoTo Finished End If TextBox2 = TextBox4 - TextBox1 TextBox2.Text = Format(TextBox2.Text, "0.0000") End If Finished: If TextBox12.Value = "" Then TextBox13.Value = "" End If If TextBox11.Value = "" Then TextBox13.Value = "" End If End Sub |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That does not take you back to TextBox11
"Rick Rothstein" wrote in message ... Try using this to activate the TextBox... TextBox11.SetFocus -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... After the msgbox is dismissed I need TextBox11 to be active. "Rick Rothstein" wrote in message ... TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") First off, you don't need to use the worksheet's Text function to do the above... VB's Format function can do it. TextBox11.Value = Format(Format(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") However, you need to break that line up into two lines in order to test if the input is a valid time... TestDateVariable = Format(Replace(TextBox11.Value, ":", ""), "00\:00") If IsDate(TestDateVariable) Then TextBox11.Value = Format(TestDateVariable, "hh:mm") ' ' Rest of your code goes here ' Else MsgBox "That is not a valid time value!!!" ' ' Not sure what you will want to do next ' End If -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... I am looking for something that will catch if the user does not enter a valid time. For example if they were to enter 0995 instead of 0955. What I need is if they do enter a wrong value that a msgbox would pop up telling them there value was not correct and then reselect the textbox so that the value can be changed. Below is my code as it stands now. Private Sub TextBox11_AfterUpdate() TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox13.Value = (TimeValue(TextBox12.Value) - TimeValue(TextBox11.Value)) * 24 TextBox13.Value = Format(TextBox13.Value, "0.0000") TextBox1.Value = CDbl("0" & TextBox13.Value) + CDbl("0" & TextBox23.Value) + CDbl("0" & TextBox33.Value) + CDbl("0" & TextBox43.Value) + CDbl("0" & TextBox53.Value) + CDbl("0" & TextBox63.Value) + CDbl("0" & TextBox14.Value) + CDbl("0" & TextBox24.Value) + CDbl("0" & TextBox34.Value) + CDbl("0" & TextBox44.Value) + CDbl("0" & TextBox54.Value) + CDbl("0" & TextBox64.Value) TextBox1.Text = Format(TextBox1.Text, "0.0000") End If End If 'Test that to see if hours worked exceeds shift length If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox2 = TextBox4 - TextBox1 End If If TextBox2.Value < 0 Then TextBox2.Value = 0 GoTo Finished End If TextBox2 = TextBox4 - TextBox1 TextBox2.Text = Format(TextBox2.Text, "0.0000") End If Finished: If TextBox12.Value = "" Then TextBox13.Value = "" End If If TextBox11.Value = "" Then TextBox13.Value = "" End If End Sub |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I just realized... you are using the AfterUpdate event. Why? What are you
doing that you think you need to use this event? -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... That does not take you back to TextBox11 "Rick Rothstein" wrote in message ... Try using this to activate the TextBox... TextBox11.SetFocus -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... After the msgbox is dismissed I need TextBox11 to be active. "Rick Rothstein" wrote in message ... TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") First off, you don't need to use the worksheet's Text function to do the above... VB's Format function can do it. TextBox11.Value = Format(Format(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") However, you need to break that line up into two lines in order to test if the input is a valid time... TestDateVariable = Format(Replace(TextBox11.Value, ":", ""), "00\:00") If IsDate(TestDateVariable) Then TextBox11.Value = Format(TestDateVariable, "hh:mm") ' ' Rest of your code goes here ' Else MsgBox "That is not a valid time value!!!" ' ' Not sure what you will want to do next ' End If -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... I am looking for something that will catch if the user does not enter a valid time. For example if they were to enter 0995 instead of 0955. What I need is if they do enter a wrong value that a msgbox would pop up telling them there value was not correct and then reselect the textbox so that the value can be changed. Below is my code as it stands now. Private Sub TextBox11_AfterUpdate() TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox13.Value = (TimeValue(TextBox12.Value) - TimeValue(TextBox11.Value)) * 24 TextBox13.Value = Format(TextBox13.Value, "0.0000") TextBox1.Value = CDbl("0" & TextBox13.Value) + CDbl("0" & TextBox23.Value) + CDbl("0" & TextBox33.Value) + CDbl("0" & TextBox43.Value) + CDbl("0" & TextBox53.Value) + CDbl("0" & TextBox63.Value) + CDbl("0" & TextBox14.Value) + CDbl("0" & TextBox24.Value) + CDbl("0" & TextBox34.Value) + CDbl("0" & TextBox44.Value) + CDbl("0" & TextBox54.Value) + CDbl("0" & TextBox64.Value) TextBox1.Text = Format(TextBox1.Text, "0.0000") End If End If 'Test that to see if hours worked exceeds shift length If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox2 = TextBox4 - TextBox1 End If If TextBox2.Value < 0 Then TextBox2.Value = 0 GoTo Finished End If TextBox2 = TextBox4 - TextBox1 TextBox2.Text = Format(TextBox2.Text, "0.0000") End If Finished: If TextBox12.Value = "" Then TextBox13.Value = "" End If If TextBox11.Value = "" Then TextBox13.Value = "" End If End Sub |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
It causes some calculations to take place on the UserForm. I had originally
used an OnChange event but it was not working consistently when the user clicked on the next cell. The AfterUpdate event has not failed no matter where the user clicked next. "Rick Rothstein" wrote: I just realized... you are using the AfterUpdate event. Why? What are you doing that you think you need to use this event? -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... That does not take you back to TextBox11 "Rick Rothstein" wrote in message ... Try using this to activate the TextBox... TextBox11.SetFocus -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... After the msgbox is dismissed I need TextBox11 to be active. "Rick Rothstein" wrote in message ... TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") First off, you don't need to use the worksheet's Text function to do the above... VB's Format function can do it. TextBox11.Value = Format(Format(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") However, you need to break that line up into two lines in order to test if the input is a valid time... TestDateVariable = Format(Replace(TextBox11.Value, ":", ""), "00\:00") If IsDate(TestDateVariable) Then TextBox11.Value = Format(TestDateVariable, "hh:mm") ' ' Rest of your code goes here ' Else MsgBox "That is not a valid time value!!!" ' ' Not sure what you will want to do next ' End If -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... I am looking for something that will catch if the user does not enter a valid time. For example if they were to enter 0995 instead of 0955. What I need is if they do enter a wrong value that a msgbox would pop up telling them there value was not correct and then reselect the textbox so that the value can be changed. Below is my code as it stands now. Private Sub TextBox11_AfterUpdate() TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox13.Value = (TimeValue(TextBox12.Value) - TimeValue(TextBox11.Value)) * 24 TextBox13.Value = Format(TextBox13.Value, "0.0000") TextBox1.Value = CDbl("0" & TextBox13.Value) + CDbl("0" & TextBox23.Value) + CDbl("0" & TextBox33.Value) + CDbl("0" & TextBox43.Value) + CDbl("0" & TextBox53.Value) + CDbl("0" & TextBox63.Value) + CDbl("0" & TextBox14.Value) + CDbl("0" & TextBox24.Value) + CDbl("0" & TextBox34.Value) + CDbl("0" & TextBox44.Value) + CDbl("0" & TextBox54.Value) + CDbl("0" & TextBox64.Value) TextBox1.Text = Format(TextBox1.Text, "0.0000") End If End If 'Test that to see if hours worked exceeds shift length If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox2 = TextBox4 - TextBox1 End If If TextBox2.Value < 0 Then TextBox2.Value = 0 GoTo Finished End If TextBox2 = TextBox4 - TextBox1 TextBox2.Text = Format(TextBox2.Text, "0.0000") End If Finished: If TextBox12.Value = "" Then TextBox13.Value = "" End If If TextBox11.Value = "" Then TextBox13.Value = "" End If End Sub |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I have not made use of the AfterUpdate event myself, but the help files for
it seems to suggest that using the BeforeUpdate event might work for you... it has a Cancel argument that if set to True, will keep the focus on your TextBox. Maybe moving the validation code there would be a way to go? -- Rick (MVP - Excel) "Pats" wrote in message ... It causes some calculations to take place on the UserForm. I had originally used an OnChange event but it was not working consistently when the user clicked on the next cell. The AfterUpdate event has not failed no matter where the user clicked next. "Rick Rothstein" wrote: I just realized... you are using the AfterUpdate event. Why? What are you doing that you think you need to use this event? -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... That does not take you back to TextBox11 "Rick Rothstein" wrote in message ... Try using this to activate the TextBox... TextBox11.SetFocus -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... After the msgbox is dismissed I need TextBox11 to be active. "Rick Rothstein" wrote in message ... TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") First off, you don't need to use the worksheet's Text function to do the above... VB's Format function can do it. TextBox11.Value = Format(Format(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") However, you need to break that line up into two lines in order to test if the input is a valid time... TestDateVariable = Format(Replace(TextBox11.Value, ":", ""), "00\:00") If IsDate(TestDateVariable) Then TextBox11.Value = Format(TestDateVariable, "hh:mm") ' ' Rest of your code goes here ' Else MsgBox "That is not a valid time value!!!" ' ' Not sure what you will want to do next ' End If -- Rick (MVP - Excel) "Patrick C. Simonds" wrote in message ... I am looking for something that will catch if the user does not enter a valid time. For example if they were to enter 0995 instead of 0955. What I need is if they do enter a wrong value that a msgbox would pop up telling them there value was not correct and then reselect the textbox so that the value can be changed. Below is my code as it stands now. Private Sub TextBox11_AfterUpdate() TextBox11.Value = Format(Application.Text(Replace(TextBox11.Value, ":", ""), "00\:00"), "hh:mm") If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox13.Value = (TimeValue(TextBox12.Value) - TimeValue(TextBox11.Value)) * 24 TextBox13.Value = Format(TextBox13.Value, "0.0000") TextBox1.Value = CDbl("0" & TextBox13.Value) + CDbl("0" & TextBox23.Value) + CDbl("0" & TextBox33.Value) + CDbl("0" & TextBox43.Value) + CDbl("0" & TextBox53.Value) + CDbl("0" & TextBox63.Value) + CDbl("0" & TextBox14.Value) + CDbl("0" & TextBox24.Value) + CDbl("0" & TextBox34.Value) + CDbl("0" & TextBox44.Value) + CDbl("0" & TextBox54.Value) + CDbl("0" & TextBox64.Value) TextBox1.Text = Format(TextBox1.Text, "0.0000") End If End If 'Test that to see if hours worked exceeds shift length If TextBox12.Value "" Then If TextBox11.Value "" Then TextBox2 = TextBox4 - TextBox1 End If If TextBox2.Value < 0 Then TextBox2.Value = 0 GoTo Finished End If TextBox2 = TextBox4 - TextBox1 TextBox2.Text = Format(TextBox2.Text, "0.0000") End If Finished: If TextBox12.Value = "" Then TextBox13.Value = "" End If If TextBox11.Value = "" Then TextBox13.Value = "" End If End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
CATCH-22 won't let me save the file | Excel Programming | |||
Catch name of range | Excel Programming | |||
Catch error | Excel Programming | |||
catch event | Excel Programming | |||
Catch-22 with Error 59 | Excel Programming |