我有一个VBA用户表单,有6个列表框。每个列表框包含同一行上另一个列表框中的相关数据,例如列表框1有一个帐户代码,列表框2有一个帐户名称等。当用户选择列表框中的一个项目时,我希望所有其他列表框都选择相应的行。我如何使用循环来实现这一点?
我知道我可以按照excelcise example显式地引用列表项,但是我觉得必须有一种方法来循环遍历可用的列表框,而不是按名称列出它们。
我有一个VBA用户表单,有6个列表框。每个列表框包含同一行上另一个列表框中的相关数据,例如列表框1有一个帐户代码,列表框2有一个帐户名称等。当用户选择列表框中的一个项目时,我希望所有其他列表框都选择相应的行。我如何使用循环来实现这一点?
我知道我可以按照excelcise example显式地引用列表项,但是我觉得必须有一种方法来循环遍历可用的列表框,而不是按名称列出它们。
2条答案
按热度按时间67up9zun1#
hmae6n7t2#
经过一点故障排除,我想我在控件集合中找到了答案。在每个列表框中,我调用一个过程,该过程采用现有列表框索引、topIndex(在使用滚动条时很有用)和它自己的名称。
arrangeIndexOfLabels过程循环访问集合中的所有控件,并且只影响类型为ListBox的控件。它更新除活动ListBox之外的所有ListBox的listIndex和topIndex。
末端子组件