Populate combobox with headings from named range

davidb50

Board Regular
Joined
Apr 25, 2014
Messages
99
Hi
I'm trying to populate a combo box with the headings from a named range. The code runs but no values appear in the list. Would appreciate it if someone could tell me what I'm doing wrong.

Code:
Private Sub cmbHeadings_Change()    
'================================================================================
'Macro purpose: Populates a combobox with the headers from a named range
'Created by:
'================================================================================
    
    Dim MyRange As Range
    Dim i As Integer
    
    Set MyRange = Range("Lists_StoreName_All") '.Offset(-1, 0)
    
    With Me.cmbHeadings
        .Clear
        For i = 1 To MyRange.Columns.Count
            .AddItem MyRange.Cell(1, i).Value
        Next i
    End With
    
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
What happens if you transfer your code to the UserForm_Initialize event procedure? Your current code will only fire when the user selects something from the ComboBox, which isn't possible when it's empty.
 
Upvote 0

davidb50

Board Regular
Joined
Apr 25, 2014
Messages
99
Works perfectly now. Many thanks for your help
What happens if you transfer your code to the UserForm_Initialize event procedure? Your current code will only fire when the user selects something from the ComboBox, which isn't possible when it's empty.
 
Upvote 0

Forum statistics

Threads
1,190,958
Messages
5,983,843
Members
439,866
Latest member
jh3268

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
Top