【问题标题】:Prevent User to Select Combo Box correctly in Macro Excel [duplicate]防止用户在宏 Excel 中正确选择组合框 [重复]
【发布时间】:2018-03-27 23:46:57
【问题描述】:

我尝试在宏中创建用户窗体并为颜色创建组合框选择。

我已成功创建组合框,如下所示,并阻止用户在不填充组合框的情况下继续。这是代码:

Private Sub UserForm_Initialize()
ComboBox1.RowSource = "Sheet1!A1:A" & Range("G" & Rows.Count).End(xlUp).Row
End Sub
--------------------------------------------
Private Sub CommandButton1_Click()

If ComboBox1.Text = "" Then
    MsgBox "Please Select Color!"
    Exit Sub

Else
Sheets("Sheet1").Range("B1").Value = ComboBox1.Value
ActiveWorkbook.Close
End If

但是,用户可以在组合框中键入随机文本,我无法阻止它。 有没有办法让用户只能从提供的来源中选择值?就是这样。

【问题讨论】:

    标签: vba excel combobox


    【解决方案1】:

    将 Combo 样式设置为 fmStyleDropDownList

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-27
      • 2019-09-19
      • 2015-06-24
      • 2013-06-23
      • 2021-07-11
      相关资源
      最近更新 更多