Use List in a macro

bullcreel

Board Regular
Joined
Aug 25, 2016
Messages
148
ActiveCell.Value = ActiveSheet.Range("A1").Value

I have the above macro, and a dozen variations of it on my worksheet. They all work great. My next step is that I want the value in "A1" to be a list, of say at least 7 items. So when i hit the macro, I want it to display the 7 items and I pick one that will display. I have tried different thing except for a User Form. Do I need to do a User Form for this or is there something I can add to my simple macro above?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
For me the userform is what you want. A few steps you need to do. Create a named range holding your values to add to the combobox for your users to select. Create the userform itself with a combobox and a commandbutton. Then you want to add the code to the userform module similar to this:

VBA Code:
Private Sub CommandButton1_Click()

ActiveCell.Value = ComboBox1.Value
Unload Me

End Sub

Private Sub UserForm_Initialize()

arr = Range("MyComboboxList")
ComboBox1.List = arr
    
End Sub

then finally in a standard module you need to create a macro to show the userform as the user demands eg

VBA Code:
Sub ShowForm()

UserForm1.Show

End Sub
 
Upvote 0
Thats all. You just run the macro when you want to put a value in the activecell. The userform pops up. Select the value. Press the command button.
 
Upvote 0
I apologize. I have never used a UserForm before. My range is called "Flyouts". I put that inplace of ("MyComboboxList"). There is nothing in my form.
 
Upvote 0
You need to create the userform now and add the combobox and commandbutton to it then add the code to the modules as above.
 
Upvote 0
Of vourse if you know the cells you want the list to appear in, rather than use Activecell, you could use a Data Validation dropdown list.
 
Upvote 0
Code:
Private Sub UserForm_Initialize()
  arr = Range("MyComboboxList")
  ComboBox1.List = arr
End Sub

Just pointing out that you do not have to assign a vertical range to an Variant variable first before assigning it to the List property of the ComboBox (or ListBox if you should be using that ever)... just assign the TRANSPOSE of the range directly.

VBA Code:
Private Sub UserForm_Initialize()
  ComboBox1.List = Application.Transpose(Range("MyComboboxList"))
End Sub

or, since you are using a named range, this shortcut method...

VBA Code:
Private Sub UserForm_Click()
  ComboBox1.List = [TRANSPOSE(MyComboboxList)]
End Sub
 
Upvote 0
Thanks Rick. That was me doing first thing that came into head when it failed.
 
Upvote 0

Forum statistics

Threads
1,214,409
Messages
6,119,339
Members
448,888
Latest member
Arle8907

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