ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   input box (https://www.excelbanter.com/excel-programming/432842-input-box.html)

thomas donino

input box
 
Hello,

can some one explain why this doesnt work?

Sub test()
Dim i as Integer
Dim max as Integer

Set max = InputBox(Prompt:="How many reports to create?, Title:="Create
Reports", Type:=1)

msgbox max
End Sub


fyi in the code window the set max is all on one line

Jacob Skaria

input box
 
Try the below
Sub test()
Dim i As Integer, varMax As Variant
varMax = "0" & InputBox("How many reports to create?", _
"Create Reports", 0)
If IsNumeric(varMax) Then MsgBox varMax
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"thomas donino" wrote:

Hello,

can some one explain why this doesnt work?

Sub test()
Dim i as Integer
Dim max as Integer

Set max = InputBox(Prompt:="How many reports to create?, Title:="Create
Reports", Type:=1)

msgbox max
End Sub


fyi in the code window the set max is all on one line


Per Jessen

input box
 
Hi

Only object variables like range objects require 'Set', and you miss a
double quote sign after the question sign. Type property is not used with
Input box function, only when you use Inputbox Method
(Application.Inputbox(...))

Sub test()
Dim i As Integer
Dim max As Integer

max = InputBox(Prompt:="How many reports to create?", Title:="Create Reports
")

MsgBox max
End Sub


Regards,
Per

"thomas donino" skrev i meddelelsen
...
Hello,

can some one explain why this doesnt work?

Sub test()
Dim i as Integer
Dim max as Integer

Set max = InputBox(Prompt:="How many reports to create?, Title:="Create
Reports", Type:=1)

msgbox max
End Sub


fyi in the code window the set max is all on one line



Dave Peterson

input box
 
First, it's better to copy directly from the VBE and paste into the body of your
message. Then typos are eliminated (no closing " in the Prompt parm).

Dim max As Integer

max = Application.InputBox(Prompt:="How many reports to create?", _
Title:="Create Reports ", Type:=1)

If max = 0 Then
MsgBox "either the user entered 0 or hit cancel"
Else
MsgBox max
End If

I like to use application.inputbox with type:=1 when I don't want to bother
validating input as a number. It's too easy to let excel/vba do that check.

thomas donino wrote:

Hello,

can some one explain why this doesnt work?

Sub test()
Dim i as Integer
Dim max as Integer

Set max = InputBox(Prompt:="How many reports to create?, Title:="Create
Reports", Type:=1)

msgbox max
End Sub

fyi in the code window the set max is all on one line


--

Dave Peterson

Dave Peterson

input box
 
ps.

Don't bother using "as integer" or "as single" in your code.

Just use:
dim Max as long
dim AnotherNumber as Double

Integers and singles should be forgotten <bg.

Dave Peterson wrote:

First, it's better to copy directly from the VBE and paste into the body of your
message. Then typos are eliminated (no closing " in the Prompt parm).

Dim max As Integer

max = Application.InputBox(Prompt:="How many reports to create?", _
Title:="Create Reports ", Type:=1)

If max = 0 Then
MsgBox "either the user entered 0 or hit cancel"
Else
MsgBox max
End If

I like to use application.inputbox with type:=1 when I don't want to bother
validating input as a number. It's too easy to let excel/vba do that check.

thomas donino wrote:

Hello,

can some one explain why this doesnt work?

Sub test()
Dim i as Integer
Dim max as Integer

Set max = InputBox(Prompt:="How many reports to create?, Title:="Create
Reports", Type:=1)

msgbox max
End Sub

fyi in the code window the set max is all on one line


--

Dave Peterson


--

Dave Peterson


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

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