Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
I am designing a form where I have some textboxes where I want the user to enter numeric value (with or without decimals). since the textbox does not have properties to restrict input data to only valid numbers, how do I do the following: (a) efficiently ensure that the data entered is a valid number (b) save the entered value (which is in text format) to a spreadsheet cell in the format of a number TIA |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi
create a macro for the keypress event of your text box like private sub textbox1_KeyPress(KeyAscii as integer) KeyAscii = textNumericOnly(KeyAscii) end sub Function textNumericOnly(KeyAscii as integer) if KeyAscii = 8 or KeyAscii = 9 then 'TAB key or backspace textNumericOnly = KeyAscii exit function end if if KeyAscii < 48 or KeyAscii 57 then textNumericOnly = 0 exit function end if textNumericOnly = KeyAscii End Function Richard Daniels -----Original Message----- Hi, I am designing a form where I have some textboxes where I want the user to enter numeric value (with or without decimals). since the textbox does not have properties to restrict input data to only valid numbers, how do I do the following: (a) efficiently ensure that the data entered is a valid number (b) save the entered value (which is in text format) to a spreadsheet cell in the format of a number TIA . |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I created a form with text box called TextBox1. In it's
key press event I put in the call to the function as you have suggested. I also did a copy-paste of your function code hereunder. And then I executed the form. I am getting a compile error as follows: ByRef argument type mismatch. The line highlighted is KeyAscii = textNumericOnly (KeyAscii) The word highlighted is "(KeyAscii)" Any idea what is going wrong? TIA -----Original Message----- Hi create a macro for the keypress event of your text box like private sub textbox1_KeyPress(KeyAscii as integer) KeyAscii = textNumericOnly(KeyAscii) end sub Function textNumericOnly(KeyAscii as integer) if KeyAscii = 8 or KeyAscii = 9 then 'TAB key or backspace textNumericOnly = KeyAscii exit function end if if KeyAscii < 48 or KeyAscii 57 then textNumericOnly = 0 exit function end if textNumericOnly = KeyAscii End Function Richard Daniels -----Original Message----- Hi, I am designing a form where I have some textboxes where I want the user to enter numeric value (with or without decimals). since the textbox does not have properties to restrict input data to only valid numbers, how do I do the following: (a) efficiently ensure that the data entered is a valid number (b) save the entered value (which is in text format) to a spreadsheet cell in the format of a number TIA . . |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
No need to call a sub. Just put it in the event:
Private Sub TextBox1_KeyPress(ByVal KeyAscii _ As MSForms.ReturnInteger) If KeyAscii = 8 Or KeyAscii = 9 Then 'TAB key or backspace Exit Sub End If If KeyAscii < 48 Or KeyAscii 57 Then KeyAscii = 0 End If End Sub -- Regards, Tom Ogilvy "L. Fuernes" wrote in message ... I created a form with text box called TextBox1. In it's key press event I put in the call to the function as you have suggested. I also did a copy-paste of your function code hereunder. And then I executed the form. I am getting a compile error as follows: ByRef argument type mismatch. The line highlighted is KeyAscii = textNumericOnly (KeyAscii) The word highlighted is "(KeyAscii)" Any idea what is going wrong? TIA -----Original Message----- Hi create a macro for the keypress event of your text box like private sub textbox1_KeyPress(KeyAscii as integer) KeyAscii = textNumericOnly(KeyAscii) end sub Function textNumericOnly(KeyAscii as integer) if KeyAscii = 8 or KeyAscii = 9 then 'TAB key or backspace textNumericOnly = KeyAscii exit function end if if KeyAscii < 48 or KeyAscii 57 then textNumericOnly = 0 exit function end if textNumericOnly = KeyAscii End Function Richard Daniels -----Original Message----- Hi, I am designing a form where I have some textboxes where I want the user to enter numeric value (with or without decimals). since the textbox does not have properties to restrict input data to only valid numbers, how do I do the following: (a) efficiently ensure that the data entered is a valid number (b) save the entered value (which is in text format) to a spreadsheet cell in the format of a number TIA . . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Data collection - aggrating forms data ?? | Excel Discussion (Misc queries) | |||
Data Forms | Excel Discussion (Misc queries) | |||
Forms and data | New Users to Excel | |||
Excel Data Entry Forms (Data, Worksheet) | Excel Discussion (Misc queries) | |||
Using data forms | Excel Discussion (Misc queries) |