Populate several comboboxes with same value

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Hi,

Userform with 4 comboboxes.
I dont wish to type the same thing 4 times so im trying to make things easier.
Having said that my attempt keeps saying compile error.
It could be that its just wrong or a mistake spotted ?

Please advise thanks


Rich (BB code):
Private Sub UserForm_Initialize()
Dim ctrl As Control
     For Each ctrl In Me.Controls
       If TypeName(ctrl) = "Combobox" Then
           LoadComboBox ctrl.Name
       End If
    Next
    ComboBox1.AddItem "A"
    ComboBox1.AddItem "B"
    ComboBox1.AddItem "C"
    ComboBox1.AddItem "D"
End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
assuming your comboboxes have their default names then one way maybe

VBA Code:
Private Sub UserForm_Initialize()
    Dim i As Long
     For i = 1 To 4
       Me.Controls("Combobox" & i).List = Array("A", "B", "C", "D")
    Next i
End Sub

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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