我一直在网上搜索试图找出 listcount -1
的含义是,但我似乎无法找到确切的答案。
为什么会有-1
在列表计数旁边?或 .list(.listcount -1,1)
那什么意识?
编辑
列表计数示例.additem a.value
.list(.listcount -1, 1) = ws.cells(A,B).value
这增加了 ws.cells(A,B)
的值到 listbox1 但我不明白为什么/如何?
或者我找到了 code
在互联网上http://www.ozgrid.com/VBA/multi-select-listbox.htm
我知道代码的目的是“如果选择了列表之一,则将列表框的值传输到单元格中”,但为什么会有 .Listbox1.Listcount -1
?
最佳答案
为了让事情更清楚,正如我所说,ListCount
开始于 1
计数时ListBox
项目或 List
.
但是ListBox Indexing
这些项目或List
开始于 0
.
在您的示例中,您尝试添加一个项目或 List
在 Multi-Column ListBox
.
看看下面的例子:
With me.ListBox1
.Add "Item1"
.List(.ListCount - 1, 1) = "Item2"
.List(.ListCount - 1, 2) = "Item3"
End With
上面的代码填充了
ListBox
最初设置为 3 列。此行
.Add "Item"
添加第一个 List
在 ListBox
.但是您需要填充其余的列。
要访问这些列,请使用
.List
具有以下语法的属性:expression.List(pvargIndex, pvargColumn)
pvargIndex
是 ListBox ListIndex
和 pvargColumns
是列号。请记住,您已经添加了 1
item
使用 .Add
属性(property)和ListIndex
那个项目是?.ListCount - 1 'which is current item count in the ListBox less one equal to 0
了解更多关于学习
ListBox
, 检查 THIS出去。另见 HERE .
以上希望对您有所帮助。
关于vba - listcount -1 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22976383/