Excel VBA Listbox 使用 SelectedIndexChanged 事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43642870/
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 12:31:21  来源:igfitidea点击:

Excel VBA Listbox use of SelectedIndexChanged event

excelvbalistboxselectedindexchanged

提问by Mike Wojcik

I am trying to utilize the Excel VBA Listbox SelectedIndexChanged event to update a textbox on the same userform with the sum of the values in one column of my listbox as the user selects each row in that listbox.

我正在尝试利用 Excel VBA 列表框 SelectedIndexChanged 事件在用户选择该列表框中的每一行时,使用列表框一列中值的总和更新同一用户窗体上的文本框。

I can not figure out how to get the code for that event handler to execute. Any suggestions? I am using Excel VBA with the latest version of excel from office 365 on a windows 10 machine. In fact i don't even see that event listed in the pulldown when i have the code window up for that userform?

我不知道如何获取该事件处理程序的代码来执行。有什么建议?我在 Windows 10 机器上使用 Excel VBA 和来自 Office 365 的最新版本的 excel。事实上,当我为该用户窗体打开代码窗口时,我什至没有看到下拉列表中列出的事件?

Thanks Mike

谢谢迈克

回答by shakespeare

Private Sub ListBox1_Change()
  // Your can do anything with it

  // Looping here
     For i = 0 To ListBox1.ListCount - 1
       If ListBox1.Selected(i) Then
        ListBox1.Selected(i) = False
       End If
     Next
  End Sub