ComboBox drop down list from Table not manually typed

LlebKcir

Board Regular
Joined
Oct 8, 2018
Messages
219
One of my user forms has a list of networks that currently I have hard coded for the drop down list using .AddItem, is there a way to point to a table containing the list to populate the combobox?

current code:

Code:
Private Sub UserForm_Initialize()

' Create dropdown list for Network
With NetworkComboBox
    .AddItem "network1"
    .AddItem "network2"
    .AddItem "network3"
    .AddItem "network4"
    .AddItem "network5"
    .AddItem "network6"
End With


' Empty group ComboBox box
GroupComboBox.Value = ""


' Set All Groups radial button default NO
NOOptionButton.Value = True


End Sub

Thank you. I have a tNetworkList table with column header and all networks that would be much easier to pull data from. I know with data verification you can create a drop down list in a cell by pointing to the table, can that also be done with the user form combo box?
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Maybe something like
Code:
   Me.ComboBox1.List = Range("Table1[name]").Value
Just change the table & header names to suit
 
Upvote 0
That simple code will replace the With loop?

Code:
NetworkComboBox.List = Range("tTable1[column_header]").Value

like so? what is the Me. ? I am guessing that is just a placeholder like i used network1 above
 
Upvote 0
In this case Me refers to the userform, I tend to use it because if you intellisense turned on you will get a list of the controls on the userform.
 
Upvote 0
Interesting that Me = userform

Rich (BB code):
Me.NetworkComboBox.List = Range("tTable1[column_header]").Value

would be correct?
 
Upvote 0
If your table is called tTable1 the the column with the networks is labelled column_header, then yes that should work.
 
Upvote 0
Fluff, final code below (redacted)

Code:
Private Sub UserForm_Initialize()

' Create dropdown list for Network
' The use of the Me. provides auto-populate to gain access for the
' data contained in tNetwork table with
' column header Name
' This one line replaces the need to manually populate the list below with
' .AddItem "Network".  That old code is left as reference.
' <rlb 9="" 17="" 2019=""> Code updated to simplify future data
Me.NetworkComboBox.List = Range("tNetwork[Name]").Value
'With NetworkComboBox         ' Old manual code, replaced with line Me.NetworkComboBox.List
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'    .AddItem "Network"
'End With


' Empty group ComboBox box
GroupComboBox.Value = ""


' Set All Groups radial button default NO
NOOptionButton.Value = True


End Sub

Replace "Network" with the proper name for the location. Fluff, the Me.ComboBox... so much simpler and will take full advantage of the tNetwork table. If that list expands, the Me.ComboBox line will address without having to manually edit the list again.</rlb>
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,208
Members
452,618
Latest member
Tam84

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