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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,215,050
Messages
6,122,868
Members
449,097
Latest member
dbomb1414

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