关于代码以检查有效电子邮件的问题

问题描述 投票:0回答:1

我使用显示的代码来评估M列中的有效电子邮件,效果很好。但是,当我在工作表中的任何位置(M列或其他位置)执行涉及多个单元格的任何操作(例如复制或粘贴多个单元格,选择和删除多行等)时,我都会收到一条错误消息,内容为

“运行时错误'13':类型不匹配”

具有结束,调试或帮助的选项。调试始终指向此代码。当我仅删除或粘贴多个单元格时,尝试保留代码但防止错误。

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
excel vba mismatch
1个回答
0
投票

您可以用target.Cells.CountLarge检查是否选择了多个单元格,或者将其添加到您的代码中看起来像这样

If Target.Cells.CountLarge = 1 Then
    ' Your code goes here
End If
© www.soinside.com 2019 - 2024. All rights reserved.