+ Reply to Thread
Results 1 to 6 of 6

excel file and throw out email addresses

Hybrid View

  1. #1
    Registered User
    Join Date
    12-18-2012
    Location
    United States
    MS-Off Ver
    MS Office 2010
    Posts
    12

    excel file and throw out email addresses

    I want to check a excel file and throw out email addresses which are entered like these formats

    1) a@a..com
    2) b@a.com.
    3) a b@a.com
    4) na
    5) n/a

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: excel file and throw out email addresses

    Do you have a list of the formats which should be deleted from your sheet?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    12-18-2012
    Location
    United States
    MS-Off Ver
    MS Office 2010
    Posts
    12

    Re: excel file and throw out email addresses

    no i don't. just the examples from above which contain spacing, no @, and must have a period after the @

  4. #4
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: excel file and throw out email addresses

    Heres a function that can be used to check valid e-mail address

    Sub email()
        Dim txtEmail As String
        txtEmail = InputBox("Type the address", "e-mail address")
         
        Dim Situacao As String
         
         ' Check e-mail syntax
        If IsEmailValid(txtEmail) Then
            Situacao = "Valid e-mail syntax!"
        Else
            Situacao = "Invalid e-mail syntax!"
        End If
         ' Shows the result
        MsgBox Situacao
    End Sub
    Function IsEmailValid(strEmail)
        Dim strArray As Variant
        Dim strItem As Variant
        Dim i As Long, c As String, blnIsItValid As Boolean
        blnIsItValid = True
         
        i = Len(strEmail) - Len(Application.Substitute(strEmail, "@", ""))
        If i <> 1 Then IsEmailValid = False: Exit Function
        ReDim strArray(1 To 2)
        strArray(1) = Left(strEmail, InStr(1, strEmail, "@", 1) - 1)
        strArray(2) = Application.Substitute(Right(strEmail, Len(strEmail) - Len(strArray(1))), "@", "")
        For Each strItem In strArray
            If Len(strItem) <= 0 Then
                blnIsItValid = False
                IsEmailValid = blnIsItValid
                Exit Function
            End If
            For i = 1 To Len(strItem)
                c = LCase(Mid(strItem, i, 1))
                If InStr("abcdefghijklmnopqrstuvwxyz_-.", c) <= 0 And Not IsNumeric(c) Then
                    blnIsItValid = False
                    IsEmailValid = blnIsItValid
                    Exit Function
                End If
            Next i
            If Left(strItem, 1) = "." Or Right(strItem, 1) = "." Then
                blnIsItValid = False
                IsEmailValid = blnIsItValid
                Exit Function
            End If
        Next strItem
        If InStr(strArray(2), ".") <= 0 Then
            blnIsItValid = False
            IsEmailValid = blnIsItValid
            Exit Function
        End If
        i = Len(strArray(2)) - InStrRev(strArray(2), ".")
        If i <> 2 And i <> 3 Then
            blnIsItValid = False
            IsEmailValid = blnIsItValid
            Exit Function
        End If
        If InStr(strEmail, "..") > 0 Then
            blnIsItValid = False
            IsEmailValid = blnIsItValid
            Exit Function
        End If
        IsEmailValid = blnIsItValid
    End Function
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  5. #5
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: excel file and throw out email addresses

    try this for e-mail addresses in A1:A10

    Sub DeleteEMail()
    Dim MyString As String
    Dim mycell, myrange As Range
    Set myrange = Sheet1.Range("A1:A10")
    For Each mycell In myrange
    MyString = mycell.Value
        If MyString > "" Then
            If Not InStr(MyString, "@") > 1 Then
            mycell.Value = ""
            End If
            If InStr(MyString, ".com.") > 1 Then
            mycell.Value = ""
            End If
            If InStr(MyString, "..com") > 1 Then
            mycell.Value = ""
            End If
            If InStr(MyString, " ") > 1 Then
            mycell.Value = ""
            End If
        End If
    Next
    End Sub

  6. #6
    Registered User
    Join Date
    12-18-2012
    Location
    United States
    MS-Off Ver
    MS Office 2010
    Posts
    12

    Re: excel file and throw out email addresses

    sorry i'm a little new to excel

    i found this http://www.excelitems.com/2010/11/va...addresses.html
    and it's perfect for what i want but i couldn't get it to work somehow. I'm using MS Excel 2010.

    nothing seems to happen when i type invalid emails in there

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1