Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Defining input box data type?

Hi,

I'm running the macro below and everything seemed OK.....I enter th
wrong numberic code I get a "Number is incorrect" message and it stops
I enter the right numeric code and it and goes on and runs anothe
macro.
Problem is, if I the user enters an incorrect alph code (e.g. ABCD) i
bombs out and shows the error as.... "Run-Time error 13 - Typ
Mismatch".
Could anyone please tell me how I can avoid this from happening, an
instead get it to produce the same "Number is incorrect" message?

When the macro interupts it highlights the line
'If CLng(myNum) = ActiveCell.Value Then'.

Many thanks!!

Chris

---------------------------------------------------------------------------

Sub CommandButton1_Click()

myNum = InputBox("Please enter your 8 digit validation code. :", "Ente
Code")

If myNum = "" Then
Exit Sub
End If

Sheets("Sheet1").Select
Range("a3").Select

If CLng(myNum) = ActiveCell.Value Then
Application.OnTime Now, "RunAnotherMacro"

Else
MsgBox "Number is incorrect"

End If

Sheets("Sheet1").Select
Range("A1").Value = myNum

End Su

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Defining input box data type?

Sub CommandButton1_Click()

myNum = InputBox("Please enter your 8 digit validation code. :", "Enter
Code")

If myNum = "" Then
Exit Sub
End If

Sheets("Sheet1").Select
Range("a3").Select

if Isnumeric(myNum) then
If CLng(myNum) = ActiveCell.Value Then
Application.OnTime Now, "RunAnotherMacro"

Else
MsgBox "Number is incorrect"
exit Sub
End If
Else
msgBox "Number is alphanumeric"
Exit Sub
End If

Sheets("Sheet1").Select
Range("A1").Value = myNum

End Sub


--
Regards,
Tom Ogilvy


Big Chris wrote in message
...
Hi,

I'm running the macro below and everything seemed OK.....I enter the
wrong numberic code I get a "Number is incorrect" message and it stops.
I enter the right numeric code and it and goes on and runs another
macro.
Problem is, if I the user enters an incorrect alph code (e.g. ABCD) it
bombs out and shows the error as.... "Run-Time error 13 - Type
Mismatch".
Could anyone please tell me how I can avoid this from happening, and
instead get it to produce the same "Number is incorrect" message?

When the macro interupts it highlights the line
'If CLng(myNum) = ActiveCell.Value Then'.

Many thanks!!

Chris

--------------------------------------------------------------------------

-

Sub CommandButton1_Click()

myNum = InputBox("Please enter your 8 digit validation code. :", "Enter
Code")

If myNum = "" Then
Exit Sub
End If

Sheets("Sheet1").Select
Range("a3").Select

If CLng(myNum) = ActiveCell.Value Then
Application.OnTime Now, "RunAnotherMacro"

Else
MsgBox "Number is incorrect"

End If

Sheets("Sheet1").Select
Range("A1").Value = myNum

End Sub


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Defining input box data type?

On Sat, 24 Jan 2004 19:30:33 -0600, Big Chris
wrote:

Hi,

I'm running the macro below and everything seemed OK.....I enter the
wrong numberic code I get a "Number is incorrect" message and it stops.
I enter the right numeric code and it and goes on and runs another
macro.
Problem is, if I the user enters an incorrect alph code (e.g. ABCD) it
bombs out and shows the error as.... "Run-Time error 13 - Type
Mismatch".
Could anyone please tell me how I can avoid this from happening, and
instead get it to produce the same "Number is incorrect" message?


There are two types of InputBox. One is the InputBox function that
you're using. The other is the InputBox method of the Excel
application object. The latter type lets you specify the type of
input. If the user puts the wrong type in, it generates an error. To
see it in action, try this:

Sub ApplicationIPBDemo()

Dim vnt As Variant
Dim l As Long

'The 1 argument tells the box that you
'want a numeric value.
vnt = Application.InputBox _
("Please enter a number.", , , , , , , 1)

If vnt = False Then Exit Sub

l = CLng(vnt)

End Sub

When the macro interupts it highlights the line
'If CLng(myNum) = ActiveCell.Value Then'.

Many thanks!!

Chris

---------------------------------------------------------------------------

Sub CommandButton1_Click()

myNum = InputBox("Please enter your 8 digit validation code. :", "Enter
Code")

If myNum = "" Then
Exit Sub
End If

Sheets("Sheet1").Select
Range("a3").Select

If CLng(myNum) = ActiveCell.Value Then
Application.OnTime Now, "RunAnotherMacro"

Else
MsgBox "Number is incorrect"

End If

Sheets("Sheet1").Select
Range("A1").Value = myNum

End Sub



---------------------------------------------------------
Hank Scorpio
- Yes, yes, I know I've been missing for a while. Long story. And don't
ask what the size of my inbox is at the moment either... 8^
scorpionet who hates spam is at iprimus.com.au (You know what to do.)
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 550
Default Defining input box data type?

Big Chris,

A lot of ways (and variations) to do this.

Replace the section of code:

If myNum = "" Then
Exit Sub
End If


with this:

If IsNumeric(mynum) Then
If Len(mynum) < 8 Then
MsgBox "Not enough Numbers"
Exit Sub
End If
If Len(mynum) 8 Then
MsgBox "Tooo!!! many Numbers"
Exit Sub
End If
Else
MsgBox "Doh!!! Don't use letters"
Exit Sub
End If

John

"Big Chris " wrote in message
...
Hi,

I'm running the macro below and everything seemed OK.....I enter the
wrong numberic code I get a "Number is incorrect" message and it stops.
I enter the right numeric code and it and goes on and runs another
macro.
Problem is, if I the user enters an incorrect alph code (e.g. ABCD) it
bombs out and shows the error as.... "Run-Time error 13 - Type
Mismatch".
Could anyone please tell me how I can avoid this from happening, and
instead get it to produce the same "Number is incorrect" message?

When the macro interupts it highlights the line
'If CLng(myNum) = ActiveCell.Value Then'.

Many thanks!!

Chris

--------------------------------------------------------------------------

-

Sub CommandButton1_Click()

myNum = InputBox("Please enter your 8 digit validation code. :", "Enter
Code")

If myNum = "" Then
Exit Sub
End If

Sheets("Sheet1").Select
Range("a3").Select

If CLng(myNum) = ActiveCell.Value Then
Application.OnTime Now, "RunAnotherMacro"

Else
MsgBox "Number is incorrect"

End If

Sheets("Sheet1").Select
Range("A1").Value = myNum

End Sub


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Defining input box data type?

Thanks guys! You've all been very helpful and I now have a nice choice
to make and can maybe add one or two features.

Your time and knowledge is much appreciated!

Regards,


---
Message posted from http://www.ExcelForum.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
I can't input anything I type on Excel. What can I do? Nothing p. nakalkn Excel Worksheet Functions 2 April 19th 12 12:17 AM
error 13 type mismatch input box cluckers Excel Discussion (Misc queries) 1 October 28th 09 07:01 PM
Exit Code Upon Cancel On Type 8 Input Box FARAZ QURESHI Excel Discussion (Misc queries) 2 March 31st 08 09:22 AM
How to modify the code for different type of input? Eric Excel Worksheet Functions 1 September 1st 07 03:58 PM
How to modify the code for different type of input? Eric Excel Discussion (Misc queries) 2 September 1st 07 12:30 AM


All times are GMT +1. The time now is 12:16 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"