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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 02:43:13  来源:igfitidea点击:

what's the meaning of listcount -1

excelvbaexcel-vbalistbox

提问by Doolie1106

I've been searching on the internet trying to find what the meaning of listcount -1is, but i can't seem to find the exact answer.

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

why is there -1beside 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 codeon 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, ListCountstarts at 1when counting ListBoxitems or List.
But ListBox Indexingof those items or Liststarts at 0. In your example, you are trying to add an item or Listin a Multi-Column ListBox.
Take a look at below example:

为了让事情更清楚,正如我所说,ListCount1计算ListBox项目或List.
ListBox Indexing在这些项目中还是List0. 在您的示例中,您正在尝试添加一个项目或ListMulti-Column ListBox.
看看下面的例子:

With me.ListBox1
    .Add "Item1"
    .List(.ListCount - 1, 1) = "Item2"
    .List(.ListCount - 1, 2) = "Item3"
End With

Above code populates a ListBoxinitially set with 3 columns.
This line .Add "Item"adds the first Listin the ListBox.
But you need to populate the rest of the columns.
To access those columns, you use .Listproperty with this syntax:

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

expression.List(pvargIndex, pvargColumn)

pvargIndexis the ListBox ListIndexand pvargColumnsis the column number.
Remember that you already added 1 itemusing the .Addproperty and the ListIndexof that item is?

pvargIndexListBox ListIndexpvargColumns是列号。
还记得您已经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.

要了解有关化脓的更多信息ListBox,请查看此内容
另请参阅此处
希望以上能以某种方式帮助你。