input box

K

Kevin

Is it possible to have an input box with two or more entry boxes in it or am
I just limited to creating user forms for that?

Thanks,
Kevin
 
J

JLGWhiz

The input box only allows one entry, although it can be of variable length.
The InputBox method offers a way to limit the input to specific data types,
whereas the InputBox function returns only strings. I don't understand the
two boxes question.
 
D

Dave Peterson

As a user, I would much rather see a userform with separate areas for each
response--or even a couple of inputboxes...

But if you wanted, you could use application.inputbox() and ask for an array to
be returned:

Option Explicit
Sub testme()
Dim myArr As Variant
Dim iCtr As Long
Dim userCancelled As Boolean

Dim resp As Long

myArr = Application.InputBox(prompt:="Three values", Type:=64 + 2, _
Default:=Array("first", "second", "third"))

userCancelled = False
For iCtr = LBound(myArr) To UBound(myArr)
If myArr(iCtr) = False Then
userCancelled = True
End If
MsgBox myArr(iCtr)
Next iCtr

If userCancelled Then
Exit Sub
End If

'more code here

End Sub

You could also use:

Sub testme2()
Dim myArr As Variant
Dim iCtr As Long
Dim userCancelled As Boolean

Dim resp As Long

myArr = Application.InputBox(prompt:="Multiple values", Type:=64)

userCancelled = False
For iCtr = LBound(myArr) To UBound(myArr)
If myArr(iCtr) = False Then
userCancelled = True
End If
MsgBox myArr(iCtr)
Next iCtr

If userCancelled Then
Exit Sub
End If

'more code here

End Sub
and have the user type the response as:

{"asdf",1,"qwer",17}

Replace the comma with the user's windows list separator
 
J

JLGWhiz

If you want two data elements that would be entered on a sheet somewhere in
separate cells, then probably the UserForm with a couple of TextBox controls
would be the easiest to work with. Dave's suggestion of using an array for
the InputBox method would need some programming savvy to work with, but is
feasible also. My personal preference would be the UserForm with TextBoxes.
 
Top