简体   繁体   English

如何在Excel VBA用户窗体中创建两列Lookup组合框

[英]How to Create Two Columns Lookup Combobox in Excel VBA UserForm

Can you please let me know how I can create a Two columns Look up combobox in Excel VBA UserForm? 你能告诉我如何在Excel VBA UserForm中创建两列查找组合框吗? I am looking to create some thing like this: 我希望创建这样的东西:

在此输入图像描述

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, 但我需要生成一个215,316,485等关联值,如锤子等等,感谢你的时间,

Fill a two-dimensional array and set the List property of the ComboBox to that array: 填充二维数组并将ComboBox的List属性设置为该数组:

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 您可能还需要相应地调整ColumnWidthsTextColumn属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM