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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,214,943
Messages
6,122,370
Members
449,080
Latest member
Armadillos

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