User input into macro

PeterTaylor

Board Regular
Joined
Aug 5, 2010
Messages
158
Dear All,
I am using excel 2007. I wish allow a user to input data from within a macro that can be used in the macro. I have been using inputbox statement but I was wondering if you can have a "picklist". For example, I am converting units and would like to to present the user with a list options (1.225,1.397,4.459, etc) to choose from. Is this possible?
Regards
Peter
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You could insert a simple userform into your project, with a listbox on it - populated either from a range in the workbook, or dynamically in the initialise event of the userform.

Insert a module into your project (if you haven't already)

Declare a variable in the module
Code:
Public num As Double

Place your calling procedure into the module:

Code:
Sub peter_code()
' all you previous code here....

UserForm1.Show
MsgBox "You chose " & num & Chr(10) & "The answer is " & num * 5

' the rest of your code here....

End Sub


Put the following code into the Userform's module:
Code:
Private Sub ListBox1_Change()
num = Me.ListBox1.Value
Unload UserForm1
End Sub


Private Sub UserForm_Initialize()
With Me.ListBox1
    .AddItem "1.225"
    .AddItem "1.397"
    .AddItem "4.459"
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,408
Members
452,912
Latest member
alicemil

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