Home » excel » How to Create Two Columns Lookup Combobox in Excel VBA UserForm

How to Create Two Columns Lookup Combobox in Excel VBA UserForm

Posted by: admin May 14, 2020 Leave a comment

Questions:

Can you please let me know how I can create a Two columns Look up combobox in Excel VBA UserForm? I am looking to create some thing like this:

enter image description here

I know we can add Items to combobox using a method like this:

Private Sub UserForm_Initialize()
  With Me.ComboBox1
    .AddItem "215"
    .AddItem "316"
    .AddItem "485"
   End With
End Sub

but I need to generate a associated value with 215,316,485 and so on valyes like hammer,…
Thanks for your time,

How to&Answers:

Fill a two-dimensional array and set the List property of the ComboBox to that array:

Dim listEntries(3, 2) As Variant

listEntries(0, 0) = "215"
listEntries(0, 1) = "Hammer"
listEntries(1, 0) = "316"
listEntries(1, 1) = "Wrench"
listEntries(2, 0) = "485"
listEntries(2, 1) = "Pliers"

Me.ComboBox1.List = listEntries

You may also need to adjust the ColumnWidths and TextColumn properties accordingly