ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Force Integer in Inputbox (https://www.excelbanter.com/excel-programming/377461-re-force-integer-inputbox.html)

Craig

Force Integer in Inputbox
 
try this:

ChangeLevel = InputBox(Question3, Title3, Default3 , , , , 1)
the comma's denote the location of the box left, right, help, help context,
type
type 1 is numeric input only and it will automatically display an error
window.


"Alex" wrote:

I have the following code that inputs a value into a cell that is typed in an
input box. How can I force the number that is typed in the input box to be
an integer? Thanks.

Sub Input_Fields()

Dim Question3, Title3, Default3, Box3
Dim ChangeLevel As Integer
Question3 = "What is the Change Level?"
Title3 = "Change Level"
Default3 = ""
ChangeLevel = InputBox(Question3, Title3, Default3)


Range("e5").Select
ActiveCell.FormulaR1C1 = ChangeLevel


End Sub




Chip Pearson

Force Integer in Inputbox
 
"Craig" wrote in message

ChangeLevel = InputBox(Question3, Title3, Default3 , , , , 1)


Nope. You missed it. First of all, you need to prefix InputBox with
Application so you call Excel's InputBox function, not VBA's InputBox. You
also need to test whether the user clicked Cancel and take appropriate
action.

Rather than using a string of commas for positional parameter notation, it
is MUCH better to used named arguments:

Dim ChangeLevel As Variant
ChangeLevel = Application.InputBox(Prompt:=Question3, _
Title:=Title3, Default:=Default3, Type:=1)
If ChangeLevel = False Then
Debug.Print "User clicked cancel"
Else
Debug.Print "User choose: " & CDbl(ChangeLevel)
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)


"Craig" wrote in message
...
try this:

ChangeLevel = InputBox(Question3, Title3, Default3 , , , , 1)
the comma's denote the location of the box left, right, help, help
context,
type
type 1 is numeric input only and it will automatically display an error
window.


"Alex" wrote:

I have the following code that inputs a value into a cell that is typed
in an
input box. How can I force the number that is typed in the input box to
be
an integer? Thanks.

Sub Input_Fields()

Dim Question3, Title3, Default3, Box3
Dim ChangeLevel As Integer
Question3 = "What is the Change Level?"
Title3 = "Change Level"
Default3 = ""
ChangeLevel = InputBox(Question3, Title3, Default3)


Range("e5").Select
ActiveCell.FormulaR1C1 = ChangeLevel


End Sub







All times are GMT +1. The time now is 01:36 PM.

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