I am trying to check some of the common email domain names when people enter them into an Excel Form. I have a spread sheet tab with names like gmail.com Comcast.net Hotmail.com etc Below is the code I am having problems with. I keep getting a Type Mismatch on this line
If (Application.Match(Domain_Name, ThisWorkbook.Sheets("Domain").Range("A1:A20"), 0)) Then GoTo Done
I have tried making Domain_Name Public String and also Variant neither seems to work. The column with the domain names is set to text. I am using Excel 2010 running on Windows 10 home. Help is greatly appreciated
If (Application.Match(Domain_Name, ThisWorkbook.Sheets("Domain").Range("A1:A20"), 0)) Then GoTo Done
Code:
Sub Text_Email_Exit(ByVal Cancel As MSForms.ReturnBoolean)If (Text_Email.Text = "") Then GoTo NoEmail
If IsEmailValid(Text_Email.Text) Then
GoTo NoEmail
Else
MsgBox "Invalid Email. No Space and must contain @ and . Please correct", vbInformation, "EMail Check"
Text_Email.SetFocus
Cancel = True
End If
NoEmail:
Text_Email.Value = LCase(Text_Email.Value)
Domain_Name = Right(Text_Email.Value, Len(Text_Email.Value) - InStr(Text_Email.Value, "@"))
MsgBox "The domain name is " & Domain_Name
If (Application.Match(Domain_Name, ThisWorkbook.Sheets("Domain").Range("A1:A20"), 0)) Then
GoTo Done
Else
DomainAnswer = MsgBox("Is our email correct? Please check carefully.", vbYesNo, "Email Check")
End If
Done:
End Sub
I have tried making Domain_Name Public String and also Variant neither seems to work. The column with the domain names is set to text. I am using Excel 2010 running on Windows 10 home. Help is greatly appreciated