ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Defining input box data type? (https://www.excelbanter.com/excel-programming/289057-defining-input-box-data-type.html)

Big Chris[_30_]

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


Tom Ogilvy

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/




Hank Scorpio

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.)

John Wilson

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/




Big Chris[_31_]

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/



All times are GMT +1. The time now is 12:20 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com