Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Good day,
I am requesting the user to enter a ten digit number into the input box and would like to test this and if not ten digits, then they must re-enter. Could somebody please help me with this, im sure simple code. thanks in advance Tempy *** Sent via Developersdex http://www.developersdex.com *** |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Put your number in to string variable eg A$
Use the following code to test the length of the string If Len(A$) <10 Then MsgBox ("Incorrect number") 'Do something else to make your user re-enter the number End If Once added to your code the user will only be able to proceed when the variable is ten characters long. Note - this will only check for string length not validity, so letters and numbers can both be used, you will need to add seperate validation for those. HTH Neil www.nwarwick.co.uk "Tempy" wrote: Good day, I am requesting the user to enter a ten digit number into the input box and would like to test this and if not ten digits, then they must re-enter. Could somebody please help me with this, im sure simple code. thanks in advance Tempy *** Sent via Developersdex http://www.developersdex.com *** |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub ab()
Dim bContinuetoLoop As Boolean Dim res As String, sStr As String Dim msg As String msg = "enter 10 digit number" Do bContinuetoLoop = False res = Application.InputBox(msg, Default:=sStr) If Len(res) < 10 Then bContinuetoLoop = True msg = "Entry is not 10 digits" & _ vbNewLine & vbNewLine & _ "Enter a 10 digit number:" ElseIf Not IsNumeric(res) Then bContinuetoLoop = True msg = "Entry is not a Number" & _ vbNewLine & vbNewLine & _ "Enter a 10 digit number:" End If If res = "" Then Exit Sub sStr = res Loop Until Not bContinuetoLoop MsgBox res End Sub -- Regards, Tom Ogilvy "Tempy" wrote in message ... Good day, I am requesting the user to enter a ten digit number into the input box and would like to test this and if not ten digits, then they must re-enter. Could somebody please help me with this, im sure simple code. thanks in advance Tempy *** Sent via Developersdex http://www.developersdex.com *** |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi,
Try this, hope it works for your purposes Sub Macro1() Dim Message, Title, MyValue Message = "Please enter the 10 digit number" Title = "10 digit number" MyValue = InputBox(Message, Title) If MyValue Like "##########" Then 'Do nothing Else Stop Dim Msg1 Msg1 = "Please reenter a 10 digit number" Response = MsgBox(Msg1) End End If End Sub Thanks, "Neil" wrote: Put your number in to string variable eg A$ Use the following code to test the length of the string If Len(A$) <10 Then MsgBox ("Incorrect number") 'Do something else to make your user re-enter the number End If Once added to your code the user will only be able to proceed when the variable is ten characters long. Note - this will only check for string length not validity, so letters and numbers can both be used, you will need to add seperate validation for those. HTH Neil www.nwarwick.co.uk "Tempy" wrote: Good day, I am requesting the user to enter a ten digit number into the input box and would like to test this and if not ten digits, then they must re-enter. Could somebody please help me with this, im sure simple code. thanks in advance Tempy *** Sent via Developersdex http://www.developersdex.com *** |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
If you do this often, as I do, you may like this "AllNumeric" function.
(There is an "IsNumeric" function, but it returns true for any numeric string including minus signs and decimal points, etc.) (main code...) Dim MyInput As String ' Do While Len(MyInput) < 10 Or Not AllNumeric(MyInput) MyInput = InputBox("Enter a 10-digit number") Loop ' MsgBox """" & MyInput & """" ' (end main code...) Private Function AllNumeric(txt As String) As Boolean ' Dim Digit As String Dim i As Long ' For i = 1 To Len(txt) Digit = Mid(txt, i, 1) AllNumeric = Digit = "0" And Digit <= "9" If Not AllNumeric Then Exit Function Next i ' AllNumeric = True ' End Function "Tempy" wrote: Good day, I am requesting the user to enter a ten digit number into the input box and would like to test this and if not ten digits, then they must re-enter. Could somebody please help me with this, im sure simple code. thanks in advance Tempy *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
InputBox vs. UserForm for Numerical Data Input | Excel Programming | |||
Numerical Input via an inputbox method | Excel Programming | |||
Numerical Input via an inputbox method | Excel Programming | |||
preventing input of illegal characters in an inputbox | Excel Programming | |||
Check on the input in an inputbox | Excel Programming |