Reputation: 1601
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
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