separate out email address

dennisli

Well-known Member
Joined
Feb 20, 2004
Messages
1,070
Good evening, I have a combined sentence with email address at the end. There is a space between email and other part.
For example, in Cell A1, it's: PO Box 132, Washington Ave, dennis789@yahoo.com.
In cell A2, it changes to: 12 DW Road, georgeyiui@hotmail.com.
How can I separete these emails out?
thanks lot.
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
This code will read the email address from the last part of the cell in column A and place it in column B:
Code:
Option Explicit 

Sub ExtractEmailAddressFromColumnAToColumnB()
    
    Dim lLastA1Row As Long
    Dim lX As Long
    
    lLastA1Row = Cells(Rows.Count, 1).End(xlUp).Row
    For lX = 1 To lLastA1Row
        If InStr(Cells(lX, 1).Value, "@") > 0 Then
            Cells(lX, 2).Value = Mid(Cells(lX, 1).Value, InStrRev(Cells(lX, 1).Value, " ") + 1, 1000)
            If Right(Cells(lX, 2).Value, 1) = "." Then
                 Cells(lX, 2).Value = Left(Cells(lX, 2).Value, Len(Cells(lX, 2).Value) - 1)
            End If
        End If
    Next

End Sub
 
Upvote 0
Is there anything in the cell after the email address? If not, you can try typing this in B1 - no VBA required.

=RIGHT(A1,LEN(A1)-FIND("?",SUBSTITUTE(A1," ","?",LEN(A1)-LEN(SUBSTITUTE(A1," ","")))))

It might be wrong, and there's definitely a shorter way to do it, but I'm not at a computer now... Might have screwed up the parentheses too.
 
Upvote 0
This formula will retrieve the text after the last space character in a text string (whether it is an email address or not)...

=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99))

The 99 assumes the text being searched always less than 100 characters long. If the text could be bigger, then change the two 99's to a number bigger than that maximum length.
 
Upvote 0
This formula will retrieve the text after the last space character in a text string (whether it is an email address or not)...

=TRIM(RIGHT(SUBSTITUTE(A1," ",REPT(" ",99)),99))

The 99 assumes the text being searched always less than 100 characters long. If the text could be bigger, then change the two 99's to a number bigger than that maximum length.

Ahh, thanks Rick! I always manage to make things too complicated ;)
I once made a table of the eight most common text-extracting formulas: First word, first two (or more) words, everything but first word, everything but first two (or more) words, and the same four; but for last instead of first. If I dig it up sometime maybe I'll post it :)
It should solve about 5% of all posts on this forum!
 
Upvote 0
Another VBA way without a loop:
Code:
Sub ExtractEmail()    
With Columns(2).Cells(1).Resize(Columns(1).Cells(1).End(xlDown).Row, 1)
        .Value = Application.Transpose(Filter(Split(Join(Application.Transpose(.Offset(, -1)), " "), " "), "@"))
    End With
End Sub
 
Upvote 0
Ahh, thanks Rick! I always manage to make things too complicated ;)
I once made a table of the eight most common text-extracting formulas: First word, first two (or more) words, everything but first word, everything but first two (or more) words, and the same four; but for last instead of first. If I dig it up sometime maybe I'll post it :)
It should solve about 5% of all posts on this forum!
I liked the idea of finding the first and last so many words from a text string, so I created a mini-blog article showing the formulas I came up with. You can find that article at this link...

Find the First and Last So Many Words in a Text String
 
Upvote 0

Forum statistics

Threads
1,203,506
Messages
6,055,806
Members
444,825
Latest member
aggerdanny

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top