Extracting phone numbers from a word string.

Preond

New Member
Joined
Feb 27, 2010
Messages
10
Hi,

Need assistance in finding solution on, how to extract phone number from a text string.

http://goo.gl/qucPe7(Link for test file)


I have searched the forum but was not able to find any solution which can help.

Thanks in Advance.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Code:
Sub FindNumbers()
 Dim ob As Object
 Set ob = CreateObject("vbscript.regexp") ' i am using excel 2007
  With ob
   .Pattern = "\b\d{11}\b"
   .Global = True
 Set matches = .Execute(Range("b2")) 'where ur string contains
    r = 3                           'where you want to paste the value
      For Each Match In matches
      Cells(r, 2).Value = Match
      r = r + 1
      Next Match
  End With

 End Sub
 
Upvote 0
Hi Preond, I meant the code window on this site but thanks I figured it out.
Did you tried the macro I gave you, it works here at my end. It will retrieve all the 11 digit numbers from the string(which is in b2 in my macro) and will start putting it from range b3 down below depending on how many numbers you got.
Give it a go
 
Upvote 0
Okay, here is a non-RegExp UDF (user defined function) that you can use to retrieve a comma/space delimited list of all 11-digit numbers in the cell's text passed into it...

Code:
Function PhoneNumbers(ByVal S As String) As String
  Dim X As Long
  For X = 1 To Len(S)
    If Mid(S, X, 11) Like "###########" Then PhoneNumbers = PhoneNumbers & ", " & Mid(S, X, 11)
  Next
  PhoneNumbers = Mid(PhoneNumbers, 3)
End Function

HOW TO INSTALL UDFs
------------------------------------
If you are new to UDFs, they are easy to install and use. To install it, simply press ALT+F11 to go into the VB editor and, once there, click Insert/Module on its menu bar, then copy/paste the above code into the code window that just opened up. That's it.... you are done. You can now use PhoneNumbers just like it was a built-in Excel function. For example,

=PhoneNumbers(A1)
 
Upvote 0

Forum statistics

Threads
1,216,060
Messages
6,128,545
Members
449,457
Latest member
ncguzzo

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