yakir;955615 said:
i have a excel .CSV file that Gmail generated for me with my contacts
in..
what i want to do is function that go over all the contacts emails one
by
one and deletes all missformated addresses that cannot be use to send
email
for them.. somthing like :
if (the cell's text is not an valid email address)
{
delete the cell ;
}
to be honest i dont know much about excel so i need somthing from
scratch..
thank you all very much..
take all the email adress to spreadsheet and save as macro enabled
xlsm or .xlm and follow below steps. Please refer to attached
spreadsheet for your reference.
Copy the below code.
Open the Excel file in which you want to use the code.
Hit Alt+F11 to open the Visual Basic Editor (VBE) window.
From the menu, choose Insert-Module.
Paste the code into the code window at right.
Save the file and close the VBE
'created and edited by bala sesharao
Public Function IsValidEmail(sEmail As String) As String
'Checks if the given Email is valid
'If Email is valid: returns empty string
'If Email is invalid: returns description of error
Dim sReason As String
Dim n As Integer
n = Len(sEmail) - InStrRev(sEmail, ".")
If sEmail <> Trim(sEmail) Then
sReason = "Leading or trailing spaces"
ElseIf Len(sEmail) <= 7 Then '-- Is (e-mail address removed) a valid email address?
sReason = "Too short"
ElseIf sEmail Like "*[!0-9a-z@._+-]*" Then
'other characters than 0-9 a-z @ . _ + - are not allowed, e.g. !
$ & ` ' * / \ = ? ^ | # % { } ~
sReason = "Invalid character"
ElseIf Not sEmail Like "*.*" Then
sReason = "Missing the ."
ElseIf Not sEmail Like "*@*" Then
sReason = "Missing the @"
ElseIf sEmail Like "*@*@*" Then
sReason = "Too many @"
ElseIf sEmail Like "[@.]*" Or sEmail Like "*[@.]" _
Or sEmail Like "*..*" Or Not sEmail Like "?*@?*.*?" Then
sReason = "Invalid format"
ElseIf n > 4 Then
'Check if suffix is between 2 (.tw etc) and 4 characters (.info
etc)
sReason = "Suffix too long"
ElseIf n < 2 Then
sReason = "Suffix too short"
Else
'If no problems, sReason is empty
sReason = "Valid Email Address"
End If
IsValidEmail = sReason
End Function
all the best
+-------------------------------------------------------------------+
|Filename: Email Validation.zip |
|Download:
http://www.excelbanter.com/attachment.php?attachmentid=152|
+-------------------------------------------------------------------+