简体   繁体   English

使用VBA将VALUES + INDEX添加到Excel中的ActiveX ComboBox

[英]Add VALUES + INDEX to ActiveX ComboBox in Excel with VBA

How can I add items and an index to a combo box, I've got the below, but it says it's an invalid argument: 我如何向组合框添加项目和索引,我得到了下面的内容,但它说这是一个无效的参数:

Me.lstDataSet.AddItem wsB.Range("B5"), wsB.Range("A5")

A5 is an integer (index) value [34] and B5 is a string/date (actual) value [04 Jan 2012]. A5是整数(索引)值[34], B5是字符串/日期(实际)值[2012年1月4日]。 For reference, code that comes before this imports the last updated/inserted record from a database. 作为参考,在此之前的代码从数据库中导入了最后更新/插入的记录。

What I want to achieve is to have the combobox display [ 001 | 我要实现的是让组合框显示[001 | String Value ], ie display two columns, which I can then reference later. 字符串值],即显示两列,我以后可以参考。

to add items to the second column, use .List 要将项目添加到第二列,请使用.List

Me.ComboBox1.Clear
Me.ComboBox1.AddItem "1"
Me.ComboBox1.List(0, 1) = "testing" ' add text in second column (0 based array)
Me.ComboBox1.AddItem "2342"
Me.ComboBox1.List(Me.ComboBox1.ListCount-1, 1) = "more testing" 
' add it to last item added, no need to remember where you are

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

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