在MultiColumn ListBox

时间:2015-11-04 13:08:52

标签: excel vba excel-vba

我搞乱了VBA,尤其是列表框。

我创建了一个搜索按钮,使用查找属性(.Find)并搜索我们在文本框中放入的数据表中的任何内容。

它可以将搜索结果添加到列表框中,但是如果我们想要搜索结果所在的整行,我们该如何添加它,而不是像vba listbox multicolumn add这样做? 怎么办,使用VBA?
甚至可能吗?
否则,没有VBA可能吗?

发生了什么:

Data table: a | b | c | d | e
            1 | 2 | 3 | 4 | 5
Search:   a 
Listbox : a

Search:   1 
Listbox : 1

Search:   2
Listbox : 2

Search:   d 
Listbox : d

我想要的":

Data table: a | b | c | d | e
            1 | 2 | 3 | 4 | 5

Search:  a
Listbox: a | b | c | d | e

Search:  1
Listbox: 1 | 2 | 3 | 4 | 5

Search:  2
Listbox: 1 | 2 | 3 | 4 | 5

Search:  d
Listbox: a | b | c | d | e

如果需要,我可以提供用于测试搜索的代码。

1 个答案:

答案 0 :(得分:1)

可以使用composing成员访问多列列表框中的项目。该成员接受两个参数作为输入:

.List

RowIndex :我们要访问的记录的行索引。请注意,列表框中的行基于零。因此,第一行的索引是 0

ColumnIndex :我们要访问的字段的列索引。请注意,多列列表框中的列也是零索引。因此,第一列的索引为 0

例如:

ListBox1.List(RowIndex, ColumnIndex)

<强>替代地

  

但是如果我们想要搜索结果所在的整行,我们该如何添加它,而不是做这样的vba listbox multicolumn add?

假设您有一个范围对象(例如'Assign values to the columns For i = 1 To 9 ListBox1.AddItem 'Create a new row ListBox1.List(i - 1, 0) = i 'Fill the first column ListBox1.List(i - 1, 1) = i * 10 ListBox1.List(i - 1, 2) = i * 100 ListBox1.List(i - 1, 3) = i * 1000 Next i )代表rngFound的结果:

.Find
相关问题