How to Create Two Columns Lookup Combobox in Excel

2019-08-01 06:19发布

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,

1条回答
淡お忘
2楼-- · 2019-08-01 07:24

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

查看更多
登录 后发表回答