input box

  • Thread starter Thread starter thomas donino
  • Start date Start date
T

thomas donino

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
 
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
 
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
 
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.
 
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>.
 
Back
Top