Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Check on the input in an inputbox

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Check on the input in an inputbox

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Check on the input in an inputbox

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 ***

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Check on the input in an inputbox

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 ***



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default Check on the input in an inputbox

Thanks so much Tom.

Tempy

*** Sent via Developersdex http://www.developersdex.com ***


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Check on the input in an inputbox

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
InputBox vs. UserForm for Numerical Data Input Chuckles123[_53_] Excel Programming 0 November 12th 04 04:40 PM
Numerical Input via an inputbox method Tom Ogilvy Excel Programming 0 August 16th 04 07:33 PM
Numerical Input via an inputbox method Bob Phillips[_6_] Excel Programming 0 August 16th 04 07:30 PM
preventing input of illegal characters in an inputbox drofnats Excel Programming 8 July 11th 04 09:25 PM
Check on the input in an inputbox Les Stout Excel Programming 2 January 14th 04 03:18 PM


All times are GMT +1. The time now is 10:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"