FlyingAura
FlyingAura

Reputation: 1601

Populate Excel VBA Combo-box with Column Headers

I want to populate a combobox with the column headers (A1 through AR1) How do I do that in Excel VBA?

Upvotes: 0

Views: 2931

Answers (1)

user248884
user248884

Reputation: 911

This code should do the trick:

Private Sub UserForm_Initialize()
Dim Cell As Range
For Each Cell In Range("A1:AR1")
    Data_UF.CB.AddItem (Cell.Value)
Next Cell  
End Sub

What its doing is: Loop through each cell from A1 to AR1, Add it to the Combobox (CB) thats in the Userform (Data_UF). This is being done at the time of initialization.

Upvotes: 2

Related Questions