vba listcount -1 是什么意思
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22976383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what's the meaning of listcount -1
提问by Doolie1106
I've been searching on the internet trying to find what the meaning of listcount -1
is, but i can't seem to find the exact answer.
我一直在互联网上搜索试图找到它的含义listcount -1
,但我似乎无法找到确切的答案。
why is there -1
beside the listcount? or .list(.listcount -1,1)
what is that mean?
为什么-1
在listcount旁边有?或者.list(.listcount -1,1)
这是什么意思?
edit
编辑
example of the listcount
列表计数的例子
.additem a.value
.additem a.value
.list(.listcount -1, 1) = ws.cells(A,B).value
.list(.listcount -1, 1) = ws.cells(A,B).value
this adds the value of ws.cells(A,B)
to the listbox1 but i don't understand why/how?
这将 的值添加ws.cells(A,B)
到 listbox1 但我不明白为什么/如何?
or i found a code
on the internet http://www.ozgrid.com/VBA/multi-select-listbox.htm
或者我code
在互联网上找到了一个http://www.ozgrid.com/VBA/multi-select-listbox.htm
i understand that the purpose of the code is "if one of the list is selected, then transfer the value of listbox into cells" but why is there .Listbox1.Listcount -1
?
我知道代码的目的是“如果选择了列表之一,则将列表框的值转移到单元格中”,但为什么会这样.Listbox1.Listcount -1
?
回答by L42
To make things clearer, as I've said, ListCount
starts at 1
when counting ListBox
items or List
.
But ListBox Indexing
of those items or List
starts at 0
.
In your example, you are trying to add an item or List
in a Multi-Column ListBox
.
Take a look at below example:
为了让事情更清楚,正如我所说,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
Above code populates a ListBox
initially set with 3 columns.
This line .Add "Item"
adds the first List
in the ListBox
.
But you need to populate the rest of the columns.
To access those columns, you use .List
property with this syntax:
上面的代码ListBox
用 3 列填充初始设置。
这条线路.Add "Item"
将第一List
的ListBox
。
但是您需要填充其余的列。
要访问这些列,请使用.List
具有以下语法的属性:
expression.List(pvargIndex, pvargColumn)
pvargIndex
is the ListBox ListIndex
and pvargColumns
is the column number.
Remember that you already added 1 item
using the .Add
property and the ListIndex
of that item is?
pvargIndex
是ListBox ListIndex
和pvargColumns
是列号。
还记得您已经item
使用.Add
属性添加了 1并且该ListIndex
项目的 是?
.ListCount - 1 'which is current item count in the ListBox less one equal to 0
To learn more about pupulating ListBox
, check THISout.
Also see HERE.
Hope above helps you somehow.