【问题标题】:Display where an error is in a message box在消息框中显示错误的位置
【发布时间】:2020-03-15 04:37:41
【问题描述】:

我使用此代码来防止输入无效电子邮件地址的文本。用户有一个带有 22 个文本框的用户窗体,供用户将地址输入到一系列单元格中。如何让消息框显示错误所在?或者,我应该把这个“检查”放在不同的地方,比如“CommandButton1_Click()”子吗?

此代码位于“Private Sub Worksheet_Change(ByVal Target As Range)”表中。

If Target.Cells.CountLarge = 1 Then
    If Target.Column = 13 And Target.Value <> "" And Evaluate("COUNTIF(" & Target.Address & ",""*@*.*"")") <> 1 Then
        Target.ClearContents
        Target.Activate
        MsgBox "Please enter a valid email address."
    End If
End If

【问题讨论】:

    标签: text msgbox


    【解决方案1】:
    If Target.Cells.CountLarge = 1 Then
        If Target.Column = 13 And Target.Value <> "" And Evaluate("COUNTIF(" & Target.Address & ",""*@*.*"")") <> 1 Then
            MsgBox "Email address ''" & Target.Value & "'' in " & Target.Address & " is not a valid email address." & _
            vbNewLine & "Please enter a valid email address."
            Target.ClearContents
            Target.Activate
        End If
    End If
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多