Sunday, March 16, 2014

How to populate a combobox located in a VBA userform using a named range in Excel

In Excel:


In VBA:

Sub populate_combobox() 'Procedure to populate a combobox located in a userform

Dim item As Range

With UserForm1.Controls("ComboBox1"'To access to properties of the userform before showing the userform
    .Clear 'Remove previous loaded values
    For Each item In Sheets(1).Range("Mycomboboxlist").Cells 'Go through all the cells of a named range
        .AddItem (item.Value) 'To populate the combobox with a value
    Next
End With

UserForm1.Show 'To display the userform

End Sub


No comments:

Post a Comment