Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
I can't input anything I type on Excel. What can I do? Nothing p. | Excel Worksheet Functions | |||
error 13 type mismatch input box | Excel Discussion (Misc queries) | |||
Exit Code Upon Cancel On Type 8 Input Box | Excel Discussion (Misc queries) | |||
How to modify the code for different type of input? | Excel Worksheet Functions | |||
How to modify the code for different type of input? | Excel Discussion (Misc queries) |