在使用VBA插入之前匹配电子邮件ID

时间:2013-05-07 12:02:08

标签: excel vba excel-vba

我在工作表1的A1中有7101个电子邮件ID。现在我想在Sheet2中插入新的电子邮件ID。我将创建一个用户表单,在插入新的电子邮件ID之前,用户应检查Sheet1中是否存在电子邮件ID。如果电子邮件ID存在,它会显示一个消息框“电子邮件已经存在”

我该怎么做?

1 个答案:

答案 0 :(得分:2)

Dim ws As Worksheet
Set ws = Sheets("Sheet 1")

Dim rg As Range
Set rg = Range("A1", ws.Range("A1").End(xlDown))

Dim emailFound As Range
Set emailFound = rg.Find("foo@bar.com", lookin:=xlValues)

If Not emailFound Is Nothing Then MsgBox "The email is already there" 
[...]

应该这样做。