Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Forcing Integer in InputBox

I used the following code in my module. I'm actually not going to set the
range value until later in the code so I remarked it out. My problem is that
if user leaves the changelevel blank an error box appears saying that,"the
formula you typed contains an error". In this code I just need the user to
be forced to type an integer, cannot leave it blank and cannot type text. If
user types text or leaves the box blank I need msgbox("you must type a
number"). What am I missing? Thanks.

Dim Question3 As String, Title3 As String
Dim ChangeLevel As Variant

Const DftInt As Integer = 0
Const NumbersOnly As Long = 1

Question3 = "What is the Change Level?"
Title3 = "Change Level"
NeedChangeLevel:
ChangeLevel = Application.InputBox(Question3, Title3, DftInt, , , , ,
NumbersOnly)
If ChangeLevel = False Then
Exit Sub
End If
'See if the result can coerced into an Int
On Error Resume Next
'Range("E5").Value = CInt(ChangeLevel)
If Err.Number < 0 Then
MsgBox "Must be a number"
GoTo NeedChangeLevel
' Range("E5").Value = CVErr(xlErrNum)
End If
On Error GoTo 0


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Forcing Integer in InputBox

Const DftInt As Integer = 0
Const NumbersOnly As Long = 1
Dim cnt as Long, vChangeLevel as Variant

Question3 = "What is the Change Level? [Mandatory]"
Title3 = "Change Level"
do
vChangeLevel = Application.InputBox(Question3, Title3, DftInt,type:=1)
cnt = cnt + 1
if cnt 4 then exit sub
Loop while typename(vChangeLevel) = "Boolean"
ChangeLevel = cint(vChangeLevel)

--
Regards,
tom Ogilvy


"Alex" wrote:

I used the following code in my module. I'm actually not going to set the
range value until later in the code so I remarked it out. My problem is that
if user leaves the changelevel blank an error box appears saying that,"the
formula you typed contains an error". In this code I just need the user to
be forced to type an integer, cannot leave it blank and cannot type text. If
user types text or leaves the box blank I need msgbox("you must type a
number"). What am I missing? Thanks.

Dim Question3 As String, Title3 As String
Dim ChangeLevel As Variant

Const DftInt As Integer = 0
Const NumbersOnly As Long = 1

Question3 = "What is the Change Level?"
Title3 = "Change Level"
NeedChangeLevel:
ChangeLevel = Application.InputBox(Question3, Title3, DftInt, , , , ,
NumbersOnly)
If ChangeLevel = False Then
Exit Sub
End If
'See if the result can coerced into an Int
On Error Resume Next
'Range("E5").Value = CInt(ChangeLevel)
If Err.Number < 0 Then
MsgBox "Must be a number"
GoTo NeedChangeLevel
' Range("E5").Value = CVErr(xlErrNum)
End If
On Error GoTo 0


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Forcing Integer in InputBox

I've tried different variations of this and if I leave the box blank, I still
get an error message that says,"the formula you typed contains an error".
I'd be OK if it said,"number not valid", but not sure why I'm getting the
error message. Thanks for your help.

"Tom Ogilvy" wrote:

Const DftInt As Integer = 0
Const NumbersOnly As Long = 1
Dim cnt as Long, vChangeLevel as Variant

Question3 = "What is the Change Level? [Mandatory]"
Title3 = "Change Level"
do
vChangeLevel = Application.InputBox(Question3, Title3, DftInt,type:=1)
cnt = cnt + 1
if cnt 4 then exit sub
Loop while typename(vChangeLevel) = "Boolean"
ChangeLevel = cint(vChangeLevel)

--
Regards,
tom Ogilvy


"Alex" wrote:

I used the following code in my module. I'm actually not going to set the
range value until later in the code so I remarked it out. My problem is that
if user leaves the changelevel blank an error box appears saying that,"the
formula you typed contains an error". In this code I just need the user to
be forced to type an integer, cannot leave it blank and cannot type text. If
user types text or leaves the box blank I need msgbox("you must type a
number"). What am I missing? Thanks.

Dim Question3 As String, Title3 As String
Dim ChangeLevel As Variant

Const DftInt As Integer = 0
Const NumbersOnly As Long = 1

Question3 = "What is the Change Level?"
Title3 = "Change Level"
NeedChangeLevel:
ChangeLevel = Application.InputBox(Question3, Title3, DftInt, , , , ,
NumbersOnly)
If ChangeLevel = False Then
Exit Sub
End If
'See if the result can coerced into an Int
On Error Resume Next
'Range("E5").Value = CInt(ChangeLevel)
If Err.Number < 0 Then
MsgBox "Must be a number"
GoTo NeedChangeLevel
' Range("E5").Value = CVErr(xlErrNum)
End If
On Error GoTo 0


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Forcing Integer in InputBox

When you use application.inputbox and type:=1, the user has to enter something
that looks like a number (or hit cancel).

That application.dialog won't let your code (or the user) continue until one of
those things is met (a number or a click on cancel).

Maybe just changing the message to something like:
Question3 = "What is the Change Level? [Mandatory]" _
& vbLf & "Please enter a number"

would make it easier for the user to know what is expected.

Alex wrote:

I've tried different variations of this and if I leave the box blank, I still
get an error message that says,"the formula you typed contains an error".
I'd be OK if it said,"number not valid", but not sure why I'm getting the
error message. Thanks for your help.

"Tom Ogilvy" wrote:

Const DftInt As Integer = 0
Const NumbersOnly As Long = 1
Dim cnt as Long, vChangeLevel as Variant

Question3 = "What is the Change Level? [Mandatory]"
Title3 = "Change Level"
do
vChangeLevel = Application.InputBox(Question3, Title3, DftInt,type:=1)
cnt = cnt + 1
if cnt 4 then exit sub
Loop while typename(vChangeLevel) = "Boolean"
ChangeLevel = cint(vChangeLevel)

--
Regards,
tom Ogilvy


"Alex" wrote:

I used the following code in my module. I'm actually not going to set the
range value until later in the code so I remarked it out. My problem is that
if user leaves the changelevel blank an error box appears saying that,"the
formula you typed contains an error". In this code I just need the user to
be forced to type an integer, cannot leave it blank and cannot type text. If
user types text or leaves the box blank I need msgbox("you must type a
number"). What am I missing? Thanks.

Dim Question3 As String, Title3 As String
Dim ChangeLevel As Variant

Const DftInt As Integer = 0
Const NumbersOnly As Long = 1

Question3 = "What is the Change Level?"
Title3 = "Change Level"
NeedChangeLevel:
ChangeLevel = Application.InputBox(Question3, Title3, DftInt, , , , ,
NumbersOnly)
If ChangeLevel = False Then
Exit Sub
End If
'See if the result can coerced into an Int
On Error Resume Next
'Range("E5").Value = CInt(ChangeLevel)
If Err.Number < 0 Then
MsgBox "Must be a number"
GoTo NeedChangeLevel
' Range("E5").Value = CVErr(xlErrNum)
End If
On Error GoTo 0



--

Dave Peterson
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
How do I add an integer to an existing integer? Aaron Excel Worksheet Functions 3 December 17th 09 09:46 PM
Forcing to Uppercase Connie Martin Excel Discussion (Misc queries) 4 February 7th 08 08:37 PM
Force Integer in Inputbox NickHK Excel Programming 2 August 27th 06 01:29 AM
forcing UDF to run Stefi Excel Worksheet Functions 4 December 29th 05 03:46 PM
Inputbox and Application.InputBox Maria[_7_] Excel Programming 1 September 20th 04 11:36 AM


All times are GMT +1. The time now is 05:08 AM.

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

About Us

"It's about Microsoft Excel"