InputBox with Array of Choices?

BAlGaInTl

Well-known Member
Joined
May 7, 2003
Messages
1,082
Ok...

I'm working on some code that requires user input. However, I want to provide them a list of 3-5 choices. I can easily get the code to work with an InputBox, but the macro actually goes and gets information from a DB. So, any mispellings, incorrect case, etc causes it to crash.

So, I've defined an array in my code called aMethod with an array of string values.

I know from reading the help, that inputbox allows the array type (64), but I can't find any examples on how to get it work....

So I have something like

strMethod = Application.Inputbox("Select Method", "Select a Method", 64)

But for the love of me, I can't figure out how to get that to use the aMethod array ...

Can someone give me a clue?

Thanks.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Isn't the array part there to allow users to enter more than one value in the inputbox?

I don't think it's meant to allow the user to make a choice from an array of values.

You could display all the values in your array in the text of the inputbox but that might be a bit unsightly.

Have you considered a userform?

You could easily have all the values in your array in a combobox or listbox to allow the user to make there choice.s
 
Upvote 0
If you enter the array as a range :- A1:A10. This works.
Code:
Dim Ray As Variant
Ray = Application.InputBox(prompt:=" ", Title:="Range Array", Type:=64)
Range("F1").Resize(UBound(Ray)) = Ray
Mick
 
Upvote 0
Isn't the array part there to allow users to enter more than one value in the inputbox?

I don't think it's meant to allow the user to make a choice from an array of values.

You could display all the values in your array in the text of the inputbox but that might be a bit unsightly.

Have you considered a userform?

You could easily have all the values in your array in a combobox or listbox to allow the user to make there choice.s

Yes, I can do it in a userform. I just thought there might be a cleaner way to do it to keep all my code in the same subroutine. I hate to make a userform for 3 choices.... :)

If you enter the array as a range :- A1:A10. This works.
Code:
Dim Ray As Variant
Ray = Application.InputBox(prompt:=" ", Title:="Range Array", Type:=64)
Range("F1").Resize(UBound(Ray)) = Ray
Mick

Where does A1:A10 come in to play there?

This is more of a query that I do from Excel, and not performed on a workbook per se. That being said, in order to use that method, I would have to create a range with the values in it first...
 
Last edited:
Upvote 0
What exactly do you want to do?

List the options the user can chose from?

If that's all then you could just try doing that with the text of the inputbox using a sort something like a numbered list.

Kind of primitive but it would work.
 
Upvote 0
What exactly do you want to do?

List the options the user can chose from?

If that's all then you could just try doing that with the text of the inputbox using a sort something like a numbered list.

Kind of primitive but it would work.

yeah...

I guess I misinterpreted the type 64 inputbox.

I ended up just creating a userform and passing the variable that way. It is the cleanest way I think.
 
Upvote 0

Forum statistics

Threads
1,224,565
Messages
6,179,549
Members
452,927
Latest member
rows and columns

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top