【问题标题】:Populate a combobox into a Userform with a selection of cells in the active sheet使用活动工作表中的单元格选择将组合框填充到用户窗体中
【发布时间】:2020-06-03 18:18:05
【问题描述】:

我刚开始在 excel 中使用 VBA,我正在尝试创建一个用户表单,我在其中从活动工作表中选择数据(一旦我复制包含它的工作表并且所有引用都应为到活动表):

  • 用户窗体名为“SystemDesignUserForm”

  • 包含它的实际工作表名为“系统设计”

  • ComboBox 被命名为“DIAComboBox”,并应列出单元格“w6:w33”中包含的数据。

我尝试了代码:

DIAComboBox.List = Range("W6:W33").Value

还有

DIAComboBox.List = ActiveSheet.Range("W6:W33").Value

并与:

DIAComboBox.List = Worksheets("System Design").Range("W6:W33").Value

但它不起作用:组合框显示为空。

你有什么建议吗?

【问题讨论】:

标签: vba combobox range userform


【解决方案1】:

您可以尝试遍历范围并填充:

'set worksheet
Dim ws as Worksheet
Set ws = Worksheets("System Design")

'loop through and collect range
    For each c in ws.Range("W6:W33")
        With Me.DIAComboBox
            .AddItem c.Value
        End With
    Next c

    Me.DIAComboBox.SetFocus

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-03
    • 1970-01-01
    相关资源
    最近更新 更多