Consulting

Results 1 to 2 of 2

Thread: Extract email out of changing string count

  1. #1
    VBAX Newbie
    Joined
    Jul 2011
    Posts
    1
    Location

    Extract email out of changing string count

    I'm having problems trying extract email out of a string of data. How can extract only the email out of:|British Columbia|fere497@yahoo.com|1|778|387|9452. How do I do this when all the data and the emails have a different string count

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum!

    [VBA]Sub Test_GetEmail()
    MsgBox GetEmail("|British Columbia|fere497@yahoo.com|1|778|387|9452")
    End Sub

    Function GetEmail(barString As String, Optional sDelimiter As String = "|") As String
    Dim element As Variant, Email As String
    Email = ""
    For Each element In Split(barString, sDelimiter)
    If InStr(element, "@") Then
    Email = element
    Exit For
    End If
    Next element
    GetEmail = Email
    End Function[/VBA]

Posting Permissions

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