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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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
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,222,095
Messages
6,163,901
Members
451,865
Latest member
dunworthc

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