excel 2010 vba user menu to store selection as variable

cmccabe

Active Member
Joined
Feb 20, 2008
Messages
396
In the below excel 2010 VBA I am trying to create a user menu that stores a selection (there are only 2 choices) in the variable strInput. That selection will be used later on. Currently the 1 or 2 from the selection being stored and not the unique 5 digit code? I added the Convert section in bold, but that is returning an overflow error. Is there a better way? Thank you very much:).

VBA

Code:
Dim Msg, Title As String
Dim MyInput As Integer

' Define message."
Msg = "Which array was used ? " _
& vbNewLine & "Enter 1 for Design: 00000" & vbNewLine _
& "Enter 2 for Design: 11111"

Title = "Selection of Application" ' Define title.

While MyInput.Value <> 1 And MyInput.Value <> 2

MyInput = InputBox(Msg, Title)
Select Case MyInput
    Case 1
        MsgBox "User chose Design 1"
    Case 2
        MsgBox "User chose Design 2"
    Case Else
        MsgBox “Invalid Entry. Try again.”
End Select

Wend

'STORE SELECTION '
Dim strInput As Integer
strInput = MyInput.Value

[B]' CONVERT USER CHOICE '
If MyInput = 1 Then
strInput = "00000"
Else
strInput = "11111"
End If[/B]

desired:

user selects 1, so 00000 would be stored in strInput but if the user selects 2, so 11111 would be stored in strInput
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
What is MyInput?

I ask because in your code you have MyInput.Value which suggests that it's some sort of object, perhaps a textbox?
 
Upvote 0
You are declaring strInput as Integer
Code:
Dim strInput As Integer
But then trying to store a string
Code:
strInput = "00000"
Else
strInput = "11111"
 
Upvote 0
Fluff

That shouldn't cause the problem(s) the OP is reporting, the "00000" and "11111" will get converted.
 
Upvote 0
Fluff

To be honest I wasn't sure myself and had to double check, been a long day.:)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,021
Latest member
Mohamed Magdi Tawfiq Emam

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