【问题标题】:Adding to sheet from Combo Box and Command Button VBA从组合框和命令按钮 VBA 添加到工作表
【发布时间】:2016-06-03 11:38:41
【问题描述】:

我正在尝试设计一个当前看起来像这样的用户表单:

组合框使用 A1:A5 生成其列表,然后将选择的任何内容链接到单元格 D12。

但是,我希望用户能够使用“添加”命令按钮根据组合框中的选项填充新列表。

例如,用户从组合框中选择 test2,单击添加,然后选择另一个选项,例如 test4,再次单击添加,它将出现在单元格 D13 中的 test2 下方。

我以前使用过 VBA,但从未真正用于表单控件,仅用于处理数据,所以这对我来说是相当新的。网上的教程大多也帮不上忙,请问大家有什么建议吗?

【问题讨论】:

    标签: vba excel combobox commandbutton


    【解决方案1】:

    此代码进入一个单独的模块:

    Sub add_click()
    
    Dim aws As Worksheet
    Dim i As Integer
    Dim firstemptyrow As Integer
    
    Set aws = ActiveSheet
    
        With aws
    
            firstemptyrow = .Cells(.Rows.count, "D").End(xlUp).Row + 1
            If firstemptyrow < 12 Then firstemptyrow = 12
    
            i = .DropDowns("dropdown1").Value
            .Range("D" & firstemptyrow).Value = .DropDowns("dropdown1").List(i)
    
        End With
    
    End Sub
    

    您需要将"dropdown1" 替换为您的组合框的名称。然后将此宏分配给您的按钮。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      • 2017-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多