Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default How to extract email address and place into a new column

I have a large spreadsheet with email addresses lumped together in the
same column as phone numbers. I am trying to extract the email
addresses and place them in a new column within the same worksheet.

I don't have much of a background in setting up macros or formulas.


Any suggestions?

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 94
Default How to extract email address and place into a new column


Hi,

Can you post an example of how your data looks líke?

Regards,
Bondi

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default How to extract email address and place into a new column


Are the phone number universally entered? 7 digits? 10 digits? -s
inbetween?

If there is a SET number of characters for the phone numbers, you can
use this:

=LEFT(A1,LEN(A1)-10)

10 being the number of characters, so you might have to change it to 7
(just numbers), 8 (numbers with a dash), 10 (just number and area
code), 11 (number, area code, and dashes in between)...


--
Bearacade


------------------------------------------------------------------------
Bearacade's Profile: http://www.excelforum.com/member.php...o&userid=35016
View this thread: http://www.excelforum.com/showthread...hreadid=558955

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default How to extract email address and place into a new column

This is a sample of what the information in the cell contains....

555-778-3230 cell 555-252-5972


555-676-5332


555-846-5352 work 555-254-5505 home 555-668-6321 cell



555-761-1436 home 555-216-1286 cell


555-682-5533 work 555-642-7987 cell 555-867-2592 home


  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,339
Default How to extract email address and place into a new column

The macro below will extract e-mail addresses. It assumes data is in column A
on Sheet1 starting in row 1. The e-mail addresses are put in columns B,C etc



Open Excel, use [Alt]+[F11] to open up the VBA editor. Choose Insert |
Module and cut and paste this into the module:


Sub GetEmailaddress()

Dim lastrow As Long, i As Long
Dim ncol As Integer, spos As Integer
Dim n As Integer, n1 As Integer, n2 As Integer
Dim searchtxt As String
Dim email As String

With Worksheets("Sheet1")

lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow
searchtxt = .Range("A" & i)
ncol = 2
spos = 1
Do
n = InStr(spos, searchtxt, "@", vbTextCompare)
If n < 0 Then
n1 = InStrRev(searchtxt, " ", n, vbTextCompare)
n2 = InStr(n, searchtxt, " ", vbTextCompare)
If n2 = 0 Then n2 = Len(searchtxt) + 1
email = Trim(Mid(searchtxt, n1, n2 - n1))
Cells(i, ncol) = email
ncol = ncol + 1
spos = n2
End If
Loop Until n = 0
Next i

End With
End Sub

To run the macro, go to View=Toolbars=Visual Basic. On the visula Basic
toolbar, click the green arrow head ("Run Macro"). The macro below will be
highlighted (if it is the only one) in the "Macro" dropdown. Click RUN.To run
the macro, go to View=Toolbars=Visual Basic. On the Visual Basic toolbar,
click the green arrow head ("Run Macro"). The macro below will be highlighted
(if it is the only one) in the "Macro" dropdown. Click RUN.

HTH

"Inquirer" wrote:

This is a sample of what the information in the cell contains....

555-778-3230 cell 555-252-5972


555-676-5332


555-846-5352 work 555-254-5505 home 555-668-6321 cell



555-761-1436 home 555-216-1286 cell


555-682-5533 work 555-642-7987 cell 555-867-2592 home





  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5
Default How to extract email address and place into a new column

When I try this, I get a run-time error it then asks me if I want to
debug when I debug the following string is highlighted.

email = Trim(Mid(searchtxt, n1, n2 - n1))

I did change the "A" to "E" as this is where the data is located.

Any additional suggestions??


Toppers wrote:
The macro below will extract e-mail addresses. It assumes data is in column A
on Sheet1 starting in row 1. The e-mail addresses are put in columns B,C etc



Open Excel, use [Alt]+[F11] to open up the VBA editor. Choose Insert |
Module and cut and paste this into the module:


Sub GetEmailaddress()

Dim lastrow As Long, i As Long
Dim ncol As Integer, spos As Integer
Dim n As Integer, n1 As Integer, n2 As Integer
Dim searchtxt As String
Dim email As String

With Worksheets("Sheet1")

lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow
searchtxt = .Range("A" & i)
ncol = 2
spos = 1
Do
n = InStr(spos, searchtxt, "@", vbTextCompare)
If n < 0 Then
n1 = InStrRev(searchtxt, " ", n, vbTextCompare)
n2 = InStr(n, searchtxt, " ", vbTextCompare)
If n2 = 0 Then n2 = Len(searchtxt) + 1
email = Trim(Mid(searchtxt, n1, n2 - n1))
Cells(i, ncol) = email
ncol = ncol + 1
spos = n2
End If
Loop Until n = 0
Next i

End With
End Sub

To run the macro, go to View=Toolbars=Visual Basic. On the visula Basic
toolbar, click the green arrow head ("Run Macro"). The macro below will be
highlighted (if it is the only one) in the "Macro" dropdown. Click RUN.To run
the macro, go to View=Toolbars=Visual Basic. On the Visual Basic toolbar,
click the green arrow head ("Run Macro"). The macro below will be highlighted
(if it is the only one) in the "Macro" dropdown. Click RUN.

HTH

"Inquirer" wrote:

This is a sample of what the information in the cell contains....

555-778-3230 cell 555-252-5972


555-676-5332


555-846-5352 work 555-254-5505 home 555-668-6321 cell



555-761-1436 home 555-216-1286 cell


555-682-5533 work 555-642-7987 cell 555-867-2592 home




  #7   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4,339
Default How to extract email address and place into a new column

Can you send me a copy of w/sheet? toppers<atjohntopley.fsnet.co.uk.
Debugging with data like yours is difficult over the NG!

"Inquirer" wrote:

When I try this, I get a run-time error it then asks me if I want to
debug when I debug the following string is highlighted.

email = Trim(Mid(searchtxt, n1, n2 - n1))

I did change the "A" to "E" as this is where the data is located.

Any additional suggestions??


Toppers wrote:
The macro below will extract e-mail addresses. It assumes data is in column A
on Sheet1 starting in row 1. The e-mail addresses are put in columns B,C etc



Open Excel, use [Alt]+[F11] to open up the VBA editor. Choose Insert |
Module and cut and paste this into the module:


Sub GetEmailaddress()

Dim lastrow As Long, i As Long
Dim ncol As Integer, spos As Integer
Dim n As Integer, n1 As Integer, n2 As Integer
Dim searchtxt As String
Dim email As String

With Worksheets("Sheet1")

lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To lastrow
searchtxt = .Range("A" & i)
ncol = 2
spos = 1
Do
n = InStr(spos, searchtxt, "@", vbTextCompare)
If n < 0 Then
n1 = InStrRev(searchtxt, " ", n, vbTextCompare)
n2 = InStr(n, searchtxt, " ", vbTextCompare)
If n2 = 0 Then n2 = Len(searchtxt) + 1
email = Trim(Mid(searchtxt, n1, n2 - n1))
Cells(i, ncol) = email
ncol = ncol + 1
spos = n2
End If
Loop Until n = 0
Next i

End With
End Sub

To run the macro, go to View=Toolbars=Visual Basic. On the visula Basic
toolbar, click the green arrow head ("Run Macro"). The macro below will be
highlighted (if it is the only one) in the "Macro" dropdown. Click RUN.To run
the macro, go to View=Toolbars=Visual Basic. On the Visual Basic toolbar,
click the green arrow head ("Run Macro"). The macro below will be highlighted
(if it is the only one) in the "Macro" dropdown. Click RUN.

HTH

"Inquirer" wrote:

This is a sample of what the information in the cell contains....

555-778-3230 cell 555-252-5972


555-676-5332


555-846-5352 work 555-254-5505 home 555-668-6321 cell



555-761-1436 home 555-216-1286 cell


555-682-5533 work 555-642-7987 cell 555-867-2592 home





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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
Automatically Sort By Reference Amount? G Excel Worksheet Functions 7 August 30th 05 10:32 AM
Does excel recognise names rather than cells? Sue Excel Worksheet Functions 9 May 22nd 05 04:51 AM
Combining workbooks with some variable field names Bob Dobalina Excel Discussion (Misc queries) 8 May 17th 05 09:48 PM
moving alternating rows to a column with the order staying the sam Duke Carey Excel Discussion (Misc queries) 0 April 27th 05 09:51 PM
10,000 addresses in column A; divided into 4 sections across. Nickornyk Excel Discussion (Misc queries) 8 March 23rd 05 10:54 PM


All times are GMT +1. The time now is 12:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"