Code to extract E-Mail addresses

Dazzawm

Well-known Member
Joined
Jan 24, 2011
Messages
3,786
Office Version
  1. 365
Platform
  1. Windows
I have thousands of rows with email addresses in column A. Problem is they are amongst other text at the beginning, middle or end. Can a code be made please to extract the email addresses in to column B next to it? I haven't posted an example as for security and its pretty self explanatory.


Thanks if you can help.
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I dont know much about regex but ive cobbled together this from stuff i just looked up on the net. Works ok it seems:

Code:
Function ExtractEmail(ByVal SearchString As String) As String

With CreateObject("vbscript.regexp")
    .Pattern = "([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)"
    .Global = True
    .IgnoreCase = True
    Set em = .Execute(SearchString)
End With

ExtractEmail = em(0).Value

End Function
 
Upvote 0
For some reason the macro button on menu bar is greyed out. Any ideas?
 
Upvote 0
But I need to insert it into a module and I cant get into VBA
 
Upvote 0
I dont know much about regex but ive cobbled together this from stuff i just looked up on the net. Works ok it seems:

Code:
Function ExtractEmail(ByVal SearchString As String) As String

With CreateObject("vbscript.regexp")
    .Pattern = "([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)"
    .Global = True
    .IgnoreCase = True
    Set em = .Execute(SearchString)
End With

ExtractEmail = em(0).Value

End Function
Worked great thanks.
 
Upvote 0
Hi,

Formula option, give this a try:


Book1
AB
1Darrens twitter is [MENTION=97701]Example[/MENTION] and his email is [email]example@gmail.com[/email]example@gmail.com
2Can you tell me whos email [email]example@hotmail.co.uk[/email] is pleaseexample@hotmail.co.uk
Sheet472
Cell Formulas
RangeFormula
B1=TRIM(MID(SUBSTITUTE(A1," ",REPT(" ",100)),FIND("@",SUBSTITUTE(SUBSTITUTE(A1," @"," |")," ",REPT(" ",100)))-100,200))
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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