extract email addresses from two column list

ajm

Well-known Member
Joined
Feb 5, 2003
Messages
2,053
Office Version
  1. 365
Platform
  1. Windows
hi, i am trying to extract email addresses from a two column list. looks like the information may have been copied and pasted from a business card application of some sort. so first column contains name and a few other bits and pieces, the second column contains email address, phone numbers, status etc. unfortunately some records seem to be six lines, some seven. i thought i might try using a pivot to create a list of the account names and then do a lookup/offset combination formula but i cannot seem to work into it the means to locate the "@" in the email address (to identify which line contains the email address). my end result will be two columns: name and email address. or maybe, since the name is already on the first line of each record, i could use some sort of formula to pull the email address up the first line of column c??

<!-- Please do not remove this header -->
<!-- Table easily created from Excel with ASAP Utilities (ASAP Utilities for Excel - The essential add-in for Excel users. FREE excel tools and macros to save time. Download Excel tools) -->
<table border="1" bordercolor="#C0C0C0" bordercolordark="#FFFFFF" cellspacing="0" cellpadding="2">
<tr>
<td bgcolor="#FFFFFF" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">Celebrant</font></td>
<td bgcolor="#FFFFFF" valign="bottom" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">Details</font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">Abbey*Dayrell, Ms</font></td>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">12 Battunga Street, Wishart QLD 4122</font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" valign="middle" style="white-space: nowrap"><font face="Tahoma" size="2" color="#00BB00">Registered</font></td>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">p(H):*(07) 3349 3236*</font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" valign="middle" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"><b>13/01/2010</b></font></td>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">p(W):*(07) 3864 0221*</font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" valign="middle" style="white-space: nowrap"><font face="Tahoma" size="2" color="#BB0000">Active</font></td>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">m:*0414 359 154</font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" align="right" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"></font></td>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#0000FF"><u>abbeyd27@bigpond.com</u></font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" align="right" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"></font></td>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"><b>Civil Ceremonies</b></font></td>
</tr>
<tr>
<td bgcolor="#FCF8ED" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">Abbott*Timothy, Mr</font></td>
<td bgcolor="#FCF8ED" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">8 Warattah Court, Wurtulla QLD 4575</font></td>
</tr>
<tr>
<td bgcolor="#FCF8ED" valign="middle" style="white-space: nowrap"><font face="Tahoma" size="2" color="#00BB00">Registered</font></td>
<td bgcolor="#FCF8ED" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">p(H):*(07) 5309 5070*</font></td>
</tr>
<tr>
<td bgcolor="#FCF8ED" valign="middle" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"><b>26/02/2010</b></font></td>
<td bgcolor="#FCF8ED" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">p(W):*(07) 5440 2000*</font></td>
</tr>
<tr>
<td bgcolor="#FCF8ED" valign="middle" style="white-space: nowrap"><font face="Tahoma" size="2" color="#BB0000">Active</font></td>
<td bgcolor="#FCF8ED" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">m:*0400 988 191</font></td>
</tr>
<tr>
<td bgcolor="#FCF8ED" align="right" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"></font></td>
<td bgcolor="#FCF8ED" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#0000FF"><u>kerriabbott@optusnet.com.au</u></font></td>
</tr>
<tr>
<td bgcolor="#FCF8ED" align="right" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"></font></td>
<td bgcolor="#FCF8ED" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"><b>Civil Ceremonies</b></font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">Aberdeen*Leonie, Mrs</font></td>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">13 Lowanna Tce, Cleveland QLD 4163</font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" valign="middle" style="white-space: nowrap"><font face="Tahoma" size="2" color="#00BB00">Registered</font></td>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">p(H):*07 3821 0025*</font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" valign="middle" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"><b>2/09/2008</b></font></td>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000">m:*0411 032 250</font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" valign="middle" style="white-space: nowrap"><font face="Tahoma" size="2" color="#BB0000">Active</font></td>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#0000FF"><u>leonie.aberdeen@bigpond.com</u></font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" align="right" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"></font></td>
<td bgcolor="#FFFFFF" valign="top" style="white-space: nowrap"><font face="Tahoma" size="2" color="#000000"><b>Civil Ceremonies</b></font></td>
</tr>
</table>
 
Excel Workbook
ABC
2Atwell*Julie-anne, Mrs16 Phillips Street, Ebbw Vale QLD 4304Example hyphenated first name
3Registeredm:*0488 745 837*
418/03/2010jnsa7@hotmail.com*
5ActiveCivil Ceremonies*
6Burton-nearhos*Jennifer, MrsPo Box 747, Capalaba QLD 4157*
7Registeredp(H):*07 3349 2023*Example hyphenated last name
82/09/2008f:*07 3245 7600**
9Activem:*0401 003 140*
10*inharmony7@hotmail.com*
11*Civil Ceremonies*
12Cooper*Elizabeth (libby), Ms51 Beryl Crescent, Holland Park QLD 4121*
13Registeredp(H):*07 3394 3530*Example preferred first name in brackets
1429/10/2008m:*0408 450 719*
15Activelibbyluis@optusnet.com.au*
16*Civil Ceremonies*
17De Heus*Ingrid, MsPo Box 34, Point Lookout QLD 4183Space in letters of last name
18Registeredp(H):*07 3409 8352**
1930/06/1995Civil Ceremonies*
20Active**
21De Palma Day*Helen, MissPo Box 152, Yeppoon QLD 47032 Spaces in letters of last name
22Registeredp(W):*0411 082 948**
234/06/2009m:*0411 082 948*
24Activebarefootweddings@live.com*
25*Civil Ceremonies*
26Dancing Free*Beth, MsPo Box 1105, Caloundra QLD 4551Space in letters of last name
27Registeredm:*0401 868 685*
283/09/2005beth@dancingfreecelebrant.com*
29ActiveCivil Ceremonies*
Sheet2


hiker95, maybe this will make it clearer. I have also included a description column (C) in the post here to show whether we are looking at a hyphenated surname, hyphenated first name, etc. Interestingly, when exceljeanie reproduces the data on screen, it inserts a "*" between the surname and firstname - and gets it right each time.

The most imprtant thing for me in the outputted material is that there is a name column (doesn't really matter if names appear as they do currently, or if they are put into First Name, Surname order) and an email column.

oh, QLD is a State: similar to Nevada, California, New Mexico, etc
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
ajm,


The format of some of the new raw data groups does not conform to the groups like the first set of data.


Sample raw data in worksheet Sheet1:


Excel Workbook
AB
1CelebrantDetails
2Abbey*Dayrell, Ms12 Battunga Street, Wishart QLD 4122
3Registeredp(H):*(07) 3349 3236*
413/01/2010p(W):*(07) 3864 0221*
5Activem:*0414 359 154
6abbeyd27@bigpond.com
7Civil Ceremonies
8Abbott*Timothy, Mr8 Warattah Court, Wurtulla QLD 4575
9Registeredp(H):*(07) 5309 5070*
1026/02/2010p(W):*(07) 5440 2000*
11Activem:*0400 988 191
12kerriabbott@optusnet.com.au
13Civil Ceremonies
14Aberdeen*Leonie, Mrs13 Lowanna Tce, Cleveland QLD 4163
15Registeredp(H):*07 3821 0025*
162/9/2008m:*0411 032 250
17Activeleonie.aberdeen@bigpond.com
18Civil Ceremonies
19Atwell*Julie-anne, Mrs16 Phillips Street, Ebbw Vale QLD 4304
20Registeredm:*0488 745 837
2118/03/2010jnsa7@hotmail.com
22ActiveCivil Ceremonies
23Burton-nearhos*Jennifer, MrsPo Box 747, Capalaba QLD 4157
24Registeredp(H):*07 3349 2023*
252/9/2008f:*07 3245 7600*
26Activem:*0401 003 140
27inharmony7@hotmail.com
28Civil Ceremonies
29Cooper*Elizabeth (libby), Ms51 Beryl Crescent, Holland Park QLD 4121
30Registeredp(H):*07 3394 3530*
3129/10/2008m:*0408 450 719
32Activelibbyluis@optusnet.com.au
33Civil Ceremonies
34De Heus*Ingrid, MsPo Box 34, Point Lookout QLD 4183
35Registeredp(H):*07 3409 8352*
3630/06/1995Civil Ceremonies
37De Palma Day*Helen, MissPo Box 152, Yeppoon QLD 4703
38Registeredp(W):*0411 082 948*
394/6/2009m:*0411 082 948
40Activebarefootweddings@live.com
41Civil Ceremonies
42Dancing Free*Beth, MsPo Box 1105, Caloundra QLD 4551
43Registeredm:*0401 868 685
443/9/2005beth@dancingfreecelebrant.com
45ActiveCivil Ceremonies
46
Sheet1





After the macro in a new worksheet Results:


Excel Workbook
ABCDEFGHIJKLM
1CelebrantMr Ms MrsRegisteredDateActiveStreetCity?Zipp(H):p(W):m:E-mail
2Dayrell AbbeyMsRegistered13/01/2010Active12 Battunga StreetWishartQLD4122(07) 3349 3236(07) 3864 02210414 359 154abbeyd27@bigpond.com
3Timothy AbbottMrRegistered26/02/2010Active8 Warattah CourtWurtullaQLD4575(07) 5309 5070(07) 5440 20000400 988 191kerriabbott@optusnet.com.au
4Leonie AberdeenMrsRegistered2/9/2008Active13 Lowanna TceClevelandQLD416307 3821 00250411 032 250leonie.aberdeen@bigpond.com
5Julie-anne AtwellMrsRegistered18/03/2010Active16 Phillips StreetEbbw ValeQLD43040488 745 837jnsa7@hotmail.com
6Jennifer Burton-nearhosMrsRegistered2/9/2008ActivePo Box 747CapalabaQLD415707 3349 20230401 003 140inharmony7@hotmail.com
7Elizabeth (libby) CooperMsRegistered29/10/2008Active51 Beryl CrescentHolland ParkQLD412107 3394 35300408 450 719libbyluis@optusnet.com.au
8Ingrid De HeusMsRegistered30/06/1995ActivePo Box 34Point LookoutQLD418307 3409 8352
9Helen De Palma DayMissRegistered4/6/2009ActivePo Box 152YeppoonQLD47030411 082 9480411 082 948barefootweddings@live.com
10Beth Dancing FreeMsRegistered3/9/2005ActivePo Box 1105CaloundraQLD45510401 868 685beth@dancingfreecelebrant.com
11
Results





Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


Code:
Option Explicit
Sub ExtractDataV2()
' hiker95, 11/20/2012
' http://www.mrexcel.com/forum/excel-questions/670029-extract-email-addresses-two-column-list.html
Dim w1 As Worksheet, wR As Worksheet
Dim c As Range, firstaddress As String
Dim r As Long, lr As Long, nr As Long, sr As Long, er As Long
Dim Area As Range, s, t
Application.ScreenUpdating = False
Set w1 = Worksheets("Sheet1")
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add(After:=w1).Name = "Results"
Set wR = Worksheets("Results")
wR.UsedRange.Clear
With wR.Cells(1, 1).Resize(, 13)
  .Value = [{"Celebrant","Mr Ms Mrs","Registered","Date","Active","Street","City","?","Zip","p(H):","p(W):","m:","E-mail"}]
  .Font.Bold = True
  .HorizontalAlignment = xlCenter
End With
With w1.Columns(2)
  Set c = .Find("Civil Ceremonies", LookIn:=xlValues, LookAt:=xlWhole)
  If Not c Is Nothing Then
    firstaddress = c.Address
    Do
      If w1.Range("B" & c.Row + 1) <> "" Then
        w1.Rows(c.Row + 1).Insert
      Else
        w1.Rows(c.Row + 2).Insert
      End If
      Set c = .FindNext(c)
    Loop While Not c Is Nothing And c.Address <> firstaddress
  End If
End With
For Each Area In w1.Range("B2", w1.Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeConstants).Areas
  With Area
    sr = .Row
    er = sr + .Rows.Count - 1
    nr = wR.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
    s = Split(w1.Cells(sr, 1), ", ")
    wR.Cells(nr, 2) = s(1)
    t = Split(s(0), "*")
    wR.Cells(nr, 1) = t(1) & " " & t(0)
    wR.Cells(nr, 3).Resize(, 3).Value = Application.Transpose(w1.Range("A" & sr + 1 & ":A" & sr + 3).Value)
    For r = sr To er - 1 Step 1
      If InStr(w1.Cells(r, 2), ", ") > 0 Then
        s = Split(w1.Cells(r, 2), ", ")
        wR.Cells(nr, 6) = s(0)
        t = Split(s(1), " ")
        If UBound(t) = 2 Then
          wR.Cells(nr, 7).Resize(, 3).Value = t
        ElseIf UBound(t) = 3 Then
          wR.Cells(nr, 7).Value = t(0) & " " & t(1)
          wR.Cells(nr, 8).Value = t(2)
          wR.Cells(nr, 9).Value = t(3)
        ElseIf UBound(t) = 4 Then
          wR.Cells(nr, 7).Value = t(0) & " " & t(1) & " " & t(2)
          wR.Cells(nr, 8).Value = t(3)
          wR.Cells(nr, 9).Value = t(4)
        End If
      ElseIf InStr(w1.Cells(r, 2), "p(H):") > 0 Then
        s = Split(w1.Cells(r, 2), "*")
        wR.Cells(nr, 10) = s(1)
      ElseIf InStr(w1.Cells(r, 2), "p(W):") > 0 Then
        s = Split(w1.Cells(r, 2), "*")
        wR.Cells(nr, 11) = s(1)
      ElseIf InStr(w1.Cells(r, 2), "m:") > 0 Then
        s = Split(w1.Cells(r, 2), "*")
        wR.Cells(nr, 12) = s(1)
      ElseIf InStr(w1.Cells(r, 2), "@") > 0 Then
        wR.Cells(nr, 13) = w1.Cells(r, 2)
      End If
    Next r
  End With
Next Area
On Error Resume Next
w1.Range("B1", w1.Range("B" & Rows.Count).End(xlUp)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
wR.Cells.EntireColumn.AutoFit
wR.Activate
Application.ScreenUpdating = True
End Sub


Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm


Then run the ExtractDataV2 macro.
 
Upvote 0
Hiker95,m i still do not get past line "wR.Cells(nr, 1) = t(1) & " " & t(0)"

it appears that the "t" value is not being picked up. I will try again tonight to get on a computer at home to upload to box.net

BTW when it errors out, this is what the results page looks like:

Excel Workbook
ABCDEFGHIJKLM
1CelebrantMr Ms MrsRegisteredDateActiveStreetCity?Zipp(H):p(W):m:E-mail
2*Ms***********
Results
 
Upvote 0
ajm,

What is the worksheet name containing the actual raw data?

I will need to see the actual workbook.

You can upload your workbook to Box Net,
sensitive data scrubbed/removed/changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
ajm,

I will need to see the actual workbook.

You can upload your workbook to Box Net,
sensitive data scrubbed/removed/changed
mark the workbook for sharing
and provide us with a link to your workbook.



If you can not give us the workbook with the actual raw data worksheet, then:

Click on the Reply to Thread button, and just put the word BUMP in the post. Then, click on the Post Quick Reply button, and someone else will assist you.
 
Upvote 0
hiker, your code is fine. I had a long think about it yesterday and tried a reverse engineer process. how would i go about trying to create a solution for someone else where they have provided existing data? I would copy their data into a new sheet and try to emulate their set up so that the result would be as close to what they required as possible. So, this started me thinking about what you were actually "seeing" when my data was posted. Turns out that Excel Jeanie adds the "*" that appears around each telephone number and inbetween the first and last names of each celebrant in the list. Your code relied on that * when splitting out the names into first name, last name order. My original data does not have asterisks where the bulletin board version does. So, to get around this splitting out the name error, i merely made
Code:
wR.Cells(nr, 1) = t(1) & " " & t(0)
into
Code:
wR.Cells(nr, 1) = w1.Cells(sr, 1)
. similarly with Phone Numbers, no * exists in the original work around each phone number. so I added an * and it all ran smoothly.

Thanks you for your patience and efforts in getting this one solved. I appreciate how frustrating it must be to see it work at your end and to be told its not working over here. Once again thanks.
 
Upvote 0

Forum statistics

Threads
1,223,710
Messages
6,174,019
Members
452,542
Latest member
Bricklin

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