Here's a User Defined Function
'---------------------------------------------------------------------------------------
' Module : Module1
' Author : Roy Cox
' Date : 26/07/2008
' Purpose : Extract email address from string
'---------------------------------------------------------------------------------------
Option Explicit
Function GetMailAdd(rCl As Range) As String
Dim sText As String
Dim iStart As Integer
Dim iEnd As Integer
Dim iPos As Integer
On Error GoTo GetMailAdd_Error
sText = rCl.Text
iPos = InStr(1, sText, "@")
iStart = InStrRev(sText, " ", iPos)
If iStart = 0 Then iStart = 1
iEnd = InStr(iPos, sText, " ")
If iEnd = 0 Then iEnd = Len(sText) + 1
GetMailAdd = Trim(Mid(sText, iStart, iEnd - iStart))
If Right(GetMailAdd, 1) = "." Then
GetMailAdd Left(GetMailAdd, Len(GetMailAdd) - 1)
Else
GetMailAdd = GetMailAdd
End If
On Error GoTo 0
Exit Function
GetMailAdd_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure GetMailAdd of Module Module1"
End Function
Use as an ordinary function
=getmailadd(A1)
Bookmarks