Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
textbox validation
I'm trying to validate user input in a userform textbox, based on a
value in a worksheet cell. The following sub works fine: Private Sub TextBoxDay_Exit(ByVal Cancel As MSForms.ReturnBoolean) If TextBoxDay.Value 0 AND < 32 Then Exit Sub MsgBox "Valid Days Only" TextBoxDay = vbNullString Cancel = True 'Keeps focus until value is null or correct End Sub However I cannot get the following code to work: Private Sub TextBoxDay_Exit(ByVal Cancel As MSForms.ReturnBoolean) If TextBoxDay.Value 0 AND TextBoxDay.Value < _ Worksheets("Begin").Cells(15, 9) Then Exit Sub MsgBox "Valid Days Only" TextBoxDay = vbNullString Cancel = True 'Keeps focus until value is null or correct End Sub I've tried a number of variations but I can't seem to find a cell reference that works. Worksheets("Begin").Cells(15, 9) = 32. Thanks for any suggestions Tim |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
textbox validation
It's the darned string comparison issue again: Private Sub TextBoxDay_Exit(ByVal Cancel As MSForms.ReturnBoolean) If CInt(TextBoxDay.Value) 0 And TextBoxDay.Value < _ CInt(Worksheets("Begin").Cells(15, 9).Value) Then Exit Sub MsgBox "Valid Days Only" TextBoxDay = vbNullString Cancel = True 'Keeps focus until value is null or correct End Sub The textbox.value property is a string value. Apparently excel looke at the Cells().Value property and assumed it was also text. You may want to do some preliminary checking to make sure the entere value is numeric before running the compare or it will bomb if an alph is entered. -- kkkni ----------------------------------------------------------------------- kkknie's Profile: http://www.excelforum.com/member.php...nfo&userid=754 View this thread: http://www.excelforum.com/showthread.php?threadid=26871 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
textbox validation
Thanks KKKnie. That worked like a charm. I was completely oblivious to the datatype difference. But I'll certainly watch out for that in the future. Tim On Tue, 12 Oct 2004 19:43:54 -0500, kkknie wrote: It's the darned string comparison issue again: Private Sub TextBoxDay_Exit(ByVal Cancel As MSForms.ReturnBoolean) If CInt(TextBoxDay.Value) 0 And TextBoxDay.Value < _ CInt(Worksheets("Begin").Cells(15, 9).Value) Then Exit Sub MsgBox "Valid Days Only" TextBoxDay = vbNullString Cancel = True 'Keeps focus until value is null or correct End Sub The textbox.value property is a string value. Apparently excel looked at the Cells().Value property and assumed it was also text. You may want to do some preliminary checking to make sure the entered value is numeric before running the compare or it will bomb if an alpha is entered. K |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Textbox validation | Excel Discussion (Misc queries) | |||
validation of input in textbox | Excel Programming | |||
textbox value validation | Excel Programming | |||
Textbox validation | Excel Programming | |||
textbox validation | Excel Programming |