+ Reply to Thread
Results 1 to 5 of 5

clean email addresses (function mid, find, left, len)

Hybrid View

  1. #1
    Registered User
    Join Date
    08-02-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    3

    clean email addresses (function mid, find, left, len)

    Hi,

    I tried to search on the forum or do it by myself but I guess my searching and vba skills are not good enough.
    I don't know if I chose a right title to explain my problem but anyway, here it is. I have a spreadsheet with

    A1 <a href="mailto:toto@vbanoob.com">toto@vbanoob.com</a>
    A2 <a href="mailto:tata@vbanoob.com">tata@vbanoob.com</a>
    A3 <a href="mailto:titi@vbanoob.com">titi@vbanoob.com</a>
    A4 <a href="mailto:tutu@vbanoob.com">tutu@vbanoob.com</a>
    etc.

    I did in Excel
    =MID(A1,FIND(">",A1)+1,100)
    to get toto@vbanoob.com</a> and
    =LEFT(A1,LEN(A1)-4)
    to get my good email address

    I would like to make a VBA function as I will have several list like that to clean.

    Thanks.

    Flo
    Last edited by FFlo; 08-05-2012 at 11:35 PM.

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: clean email addresses (function mid, find, left, len)

    Heres a Function that you can use

    Function GetEmailAddress(RngEmail As Range)
     Dim pos As Long
     Dim posend As Long
     
        If Len(RngEmail.Value) = 0 Then
            GetEmailAddress = ""
            Exit Function
        End If
        
        pos = InStr(1, RngEmail.Value, ">") + 1
        posend = InStr(pos, RngEmail.Value, "</a>", vbTextCompare)
        
        GetEmailAddress = Mid(RngEmail.Value, pos, posend - pos)
            
    End Function

  3. #3
    Registered User
    Join Date
    08-02-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: clean email addresses (function mid, find, left, len)

    Thank you Mike. Works like a charm.

    I don't know how to make it automatic for a range in VBA. I tried that but it was a total failure.

    Range("B1:B99").Value = GetEmailAddress(Range("A1:A99"))

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: clean email addresses (function mid, find, left, len)

    Loop thru the range, something like this.

    Sub test()
        For i = 1 To 99
            Cells(i, "B") = GetEmailAddress(Cells(i, "A"))
        Next
    End Sub

  5. #5
    Registered User
    Join Date
    08-02-2012
    Location
    Sydney
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: clean email addresses (function mid, find, left, len)

    Thank you Mike for sharing your expertise with a newbie like me. That works perfectly. Cheers !

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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