Populate ComboBoxes from Module?

poopiebear

New Member
Joined
Nov 19, 2010
Messages
41
Hello All,

I have several UserForms with ComboBoxes that need to populated with the same data. To prevent having to code each UserForm with the contents of the ComboBoxes, is it possible to call up code from a Module? I tried it and it gave me errors. I think one issue is that I'm populating my ComboBoxes upon Activating the UserForm. Here is the code that works that I have on each UserForm.

Thanks for any help!

Code:
Private Sub UserForm_Activate()
 
With Me
   'This will create a vertical scrollbar
    .ScrollBars = fmScrollBarsVertical
 
    'Change the values of 2 as Permission your requirements
    .ScrollHeight = .InsideHeight * 2
    .ScrollWidth = .InsideWidth * 9
End With
 
TextBox1.SetFocus
 
With CommandButton1
    .Caption = ""
End With
 
With ComboBox1
    .AddItem ""
    .AddItem "Mr."
    .AddItem "Mrs."
    .AddItem "Ms."
End With
 
With ComboBox2
    .AddItem ""
    .AddItem "Male"
    .AddItem "Female"
End With
 
'There are other actions here that are specific to each UserForm
 
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
You could use the .List property instead, and in the module have functions that return a variant array, for each list. Something like

Code:
'Userform module

ComboBox1.List = GetTitles()

'Module 
Function GetTitles() As Variant
  GetTitles = Array("", "Mr.", "Mrs.", "Ms.")
End Function
 
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,833
Members
452,947
Latest member
Gerry_F

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