listcount -1是什么意思

Doo*_*106 1 excel vba listbox excel-vba

我一直在网上搜索试图找到它的含义listcount -1,但我似乎无法找到确切的答案.

为什么-1在名单旁边?或者.list(.listcount -1,1)是什么意思?

编辑

listcount的示例

.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?

L42*_*L42 6

正如我所说的那样,为了让事情更加清晰,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
Run Code Online (Sandbox Code Playgroud)

上面的代码填充了一个ListBox包含3列的初始集.
这条线路.Add "Item"将第一List的ListBox.
但是您需要填充其余列.
要访问这些列,请使用.List具有以下语法的属性:

expression.List(pvargIndex, pvargColumn)
Run Code Online (Sandbox Code Playgroud)

pvargIndex是ListBox ListIndex和pvargColumns列号.
请记住,您已经item使用该.Add属性添加了1 ListIndex,该项目的属性是?

.ListCount - 1 'which is current item count in the ListBox less one equal to 0
Run Code Online (Sandbox Code Playgroud)

要了解有关瞳孔化的更多信息ListBox,请查看此信息.
另见这里.
希望上面以某种方式帮助你.