在MultiColumn列表框中添加行
我正在搞VBA,特别是与列表框。
我创build了一个searchbutton,它使用一个find属性(.Find),并search我们放入数据表的文本框中的任何内容。
它可以将search结果添加到列表框,但是如果我们希望从search结果所在的整行开始,我们如何添加它,而不是像这样做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
如果需要,我可以提供我用来testingsearch的代码。
可以使用.List
成员访问多列列表框中的项目。 该成员接受两个参数作为input:
ListBox1.List(RowIndex, ColumnIndex)
RowIndex :我们想要访问的logging的行索引。 注意列表框中的行是基于零的。 因此,第一行的索引是0 。
ColumnIndex :我们想要访问的字段的列索引。 请注意多列列表框中的列也是零索引。 因此,第一列的索引为0 。
例如 :
'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
另外
但是如果我们想从search结果所在的整行开始,我们如何添加它,而不是像这样做vba listbox multicolumn add?
假设你有一个范围对象(例如, rngFound
),它代表你的.Find
的结果:
Me.ListBox1.Clear Me.ListBox1.ColumnCount = rngFound.Columns.Count Me.ListBox.RowSource = rngFound.Address