Strip e-mail from cell

Keeper4826

New Member
Joined
Nov 6, 2006
Messages
47
I have a spreadsheet which has a "User Description" column. In this column, most users have data that looks similar to this:

APPLICATION - john.smith@mycompany.com
APPWEB - jane-doe@somecompany.com
APPWEB - john_doe@othercompany.com
APPLICATION - TP - paul@acompany.com
APP/APPWeb/DEV - paulsm@thecompany.com

There are also cells in this column which literally have a sentence long description, but those are not my focus. What I need to do is find a way to strip out the e-mail address found in the examples above and copy them into a new cell (the same row for the corresponding user). I don't know where to begin for this. Can anybody help?
 
erik.van.geit:

I've been doing it for a while now. The MOREFUNC Regular Expressions page was where I started with MOREFUNC's regular expression functions, then observing VBA posts regarding it, I bought a book too, but looking things up on the web as I've needed them has proven to be very helpful.

I didn't use it as a sheet function because the op didn't want to copy it to all the other cells.
 
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hotpepper, you too?? :LOL:
We saw posting jindon, then Richard some of this "regular expressions" stuff. Now you too! Still Chinese for me... Where did you learn it?

Why not use it as a sheetfunction?
Code removed

We can notice that your function also extracts emailaddresses from the "middle" of the string as you can see in B7:B11.

Yesterday I posted this function, but it seems that it didn't get through :confused:
Code removed

best regards,
Erik

No offense inteded Erik. I'm just not all that familiar with macros, so I wasn't sure where to, or rather how to, apply your code. I'm going to keep playing with these suggestions to better learn the program.
 
Upvote 0
Keeper4826, I didn't feel offended :biggrin:

Hotpepper, thank you for the reponse: once I'll understand the syntax ...
 
Upvote 0
If the email can be in the middle of the string
   A                                          B                          
 7 APPLICATION - john.smith@mycompany.com +++ john.smith@mycompany.com   
 8 APPWEB - jane-doe@somecompany.com other ++ jane-doe@somecompany.com   
 9 APPWEB - john_doe@othercompany.com more    john_doe@othercompany.com  
10 APPLICATION - TP - paul@acompany.com etc   paul@acompany.com          
11 APP/APPWeb/DEV - paulsm@thecompany.com     paulsm@thecompany.com      

Sheet1

[Table-It] version 07 by Erik Van Geit
Hi
Just for a fun
Code:
Function erik(txt As String) As String
With CreateObject("VBScript.RegExp")
    .Pattern = "^[a-z0-9][a-z0-9_\.\-]+@[a-z0-9\-\.]+(\.[a-z]{2,3})+$"
    .IgnoreCase = True
    erik = .execute(txt)(0)
End With
End Function

Some domain includes like .co.uk, .co.jp, .ne.jp etc...
 
Upvote 0
OK, let the fun go on :)
could you check that again, jindon?
seems to return #VALUE! for all the given examples
I tried changing the code to no avail. Even replacing "erik" by "jindon" didn't help :LOL:

have a nice day,
Erik
 
Upvote 0
I think this would fix it:

Code:
Function erik(txt As String) As String
With CreateObject("VBScript.RegExp")
    .Pattern = "[a-z0-9][a-z0-9_\.\-]+@[a-z0-9\-\.]+(\.[a-z]{2,3})+"
    .IgnoreCase = True
    erik = .Execute(txt)(0)
End With
End Function
 
Upvote 0
Yes, hotpepper, that works for me too.
If someone is interested to avoid #value
Code:
Function jindon(txt As String) As String
    With CreateObject("VBScript.RegExp")
        .Pattern = "[a-z0-9][a-z0-9_\.\-]+@[a-z0-9\-\.]+(\.[a-z]{2,3})+"
        .IgnoreCase = True
        On Error Resume Next
        jindon = .Execute(txt)(0)
        'If jindon = vbNullString Then jindon = "no valid email"
    End With
End Function
have a nice weekend!
Erik

EDIT: corrected codetags
 
Upvote 0
No need for On Error you just need to test the string first:

Code:
Function erik(txt As String) As String
With CreateObject("VBScript.RegExp")
    .Pattern = "[a-z0-9][a-z0-9_\.\-]+@[a-z0-9\-\.]+(\.[a-z]{2,3})+"
    .IgnoreCase = True
    If .test(txt) Then erik = .Execute(txt)(0)
End With
End Function
 
Upvote 0
you are learning me some stuff :) thanks!

Though I think that would be slower, assuming that the "test" and "execute" take the same amount of time... I'll test a bit now...

EDIT: didn't test with chrono, not sure, but I do not want to go to the bottom for this :) I'll leave it to someone else if he wants to test
 
Upvote 0

Forum statistics

Threads
1,215,373
Messages
6,124,555
Members
449,170
Latest member
Gkiller

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