Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Office > Excel

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 06-18-2009, 12:57 PM
zssteen zssteen is offline Windows Vista Office 2007 (Version 12.0)
Novice
 
Join Date: Jun 2009
Posts: 1
zssteen is on a distinguished road
Default Extract email address from field

I had a list of several thousand email addresses I pulled from a number of mailing lists I manage. I planned to migrate them to a new email management system. The problem is that some entries included the recipient's name followed by the email address surrounded in greater than/less than signs (<>).

For example - John Doe <jdoe@domain.com>

I wanted to write a script that would extract just the email address.

After some trial and error I got it working. I am posting it for the benefit of those who do not know Visual Basic and for those who do but don't feel like figuring it out themselves.

Here is the script:
=MID(B2,SEARCH("<",B2)+1,SEARCH(">",B2)-SEARCH("<",B2)-1)

B2 is the field in which the email address with the name lies.

That works very nicely unless there are some fields that contain only the email address. With this script those would return a #VALUE error since the script can't find any ">" signs.

To solve this I just add and IF/THEN statement as follows:
=IF(RIGHT(B4821, 1)=">",MID(B4821,SEARCH("<",B4821)+1,SEARCH(">",B4 821)-SEARCH("<",B4821)-1),B4821)

I also had an issue in that some of the email address-only entries were preceded by a space. To make sure that is trimmed off I use the TRIM command:
=TRIM(IF(RIGHT(B4821, 1)=">",MID(B4821,SEARCH("<",B4821)+1,SEARCH(">",B4 821)-SEARCH("<",B4821)-1),B4821))

Run that and I get what just the email address and nothing else: jdoe@domain.com

--Zev Steen
Reply With Quote
  #2  
Old 06-19-2009, 06:32 AM
Bird_FAT's Avatar
Bird_FAT Bird_FAT is offline Windows 7 Office 2007 (Version 12.0)
Super Moderator
 
Join Date: Apr 2009
Location: South East
Posts: 281
Bird_FAT is on a distinguished road
Default

Nice post - Thanks Zev!
__________________

Bird

If my post has helped, please add to my reputation in return - Thanks!

Windows XP > Office 2003
Windows 7 > Office 2007

MASTER+

Reply With Quote
Reply

Bookmarks

Tags
email, script, visualbasic

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I fill in form I received in email that used underlines instead of text field Gail L. Word 2 05-17-2009 04:38 PM
EMAIL address change warrencassell Word 8 12-11-2008 12:22 AM
Auto entry of email address (who I'm sending to) Miket Outlook 5 12-10-2008 07:41 PM
Hiding the email address John Word 0 01-10-2008 07:39 PM
Same email address on 2 or 3 computers Bob Newton Outlook 1 10-30-2007 08:18 PM


All times are GMT -4. The time now is 12:33 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.