【问题标题】:HOW to Code "If textbox is not empty then Msgbox "Invalid"如何编码“如果文本框不为空,则 Msgbox“无效”
【发布时间】:2023-04-11 02:12:01
【问题描述】:

我在编码时需要帮助

"如果文本框不为空则 Msgbox "无效"

我知道空是“”但我怎么写不空? 谢谢!

【问题讨论】:

标签: excel vba textbox is-empty msgbox


【解决方案1】:

非常基本的问题。试试TEXTBOX<>""

Private Sub CommandButton1_Click()
    If Me.TextBox1 <> "" Then
        MsgBox "Invalid"
    End If
End Sub

你也可以使用LEN()函数。

If Len(Me.TextBox1) > 0 Then
    MsgBox "Invalid"
End If

【讨论】:

  • 对不起,我是 VBA 的新手,你能告诉我 Me.Textbox1 中的 Me 在这里代表什么吗?
  • @Damandeep Me 代表您正在处理的当前表格。您也可以使用UserForm1.TextBox1 之类的表单名称。即使您只能使用文本框名称,例如 If Len(TextBox1) &gt; 0 Then ...
  • 我有一个输入框,如果它是空的,我必须从 Me.InputBox 开始吗?
  • @Damandeep 对于输入框你可以试试If Len(InputBox("Enter data.")) &gt; 0 Then
猜你喜欢
  • 1970-01-01
  • 2017-10-10
  • 1970-01-01
  • 1970-01-01
  • 2020-02-25
  • 2012-07-31
  • 2021-01-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多