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

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
1) There are two numbers here. Do you want to extract both? Will there always be two?
2) Will the numbers always follow the same format? (ie 11 characters with no -'s)
3) If the numbers will come in different formats, show the formats that the macro should be able to handle.
4) How do you want the numbers reported? What if there are multiple numbers?
 
Upvote 0
1) There can be multiple numbers and it would be great i can get both the number's.
2) yes.
3) only 1 format.
4) separated by ","

Thank you for your assistance.
 
Upvote 0
Hi,

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

http://goo.gl/qucPe7(Link for test file)
1. Will your numbers always be listed next to each other (delimited with commas) as shown?

2. If the answer to #1 is "yes", then will those numbers always follow the words "Contact. No:-" (with the period after the word "Contact" as shown and with the ":-" after the word "No" also as shown)?
 
Upvote 0
I think those are Indian mobile numbers. So if any one of the mobile numbers is fine then following can be used assuming the first digit will always be 0.
="0"&MAX(IFERROR(--MID(B2,ROW($A$1:$A$999),10),0))
To be array entered [CTRL + SHIFT + ENTER]

If the numbers are either 10/11 digits with a possibility of first non zero number.
=MID(B2,FIND(MAX(IFERROR(--MID(B2,ROW($A$1:$A$999),11),0)),B2,1)-(LEN(MAX(IFERROR(--MID(B2,ROW($A$1:$A$999),11),0)))=10),11)
 
Upvote 0
I think those are Indian mobile numbers. So if any one of the mobile numbers is fine then following can be used assuming the first digit will always be 0.
="0"&MAX(IFERROR(--MID(B2,ROW($A$1:$A$999),10),0))
To be array entered [CTRL + SHIFT + ENTER]

If the numbers are either 10/11 digits with a possibility of first non zero number.
=MID(B2,FIND(MAX(IFERROR(--MID(B2,ROW($A$1:$A$999),11),0)),B2,1)-(LEN(MAX(IFERROR(--MID(B2,ROW($A$1:$A$999),11),0)))=10),11)
How will either of these make a comma separated list (see Item #4 in Message #3)?
 
Upvote 0
Can you explain what the -- does in front of your MID? Sorry if I'm going off topic here. Don't mean to derail the discussion.
 
Last edited:
Upvote 0
Hi Rick,

1. it will be either delimited with a comma or a space,
2. No, the numbers might follow the words like Mobile No. OR Phone No.

Thank you for your assistance.
 
Upvote 0
A simple regex can give the solution..

"Can someone please tell me how to get the code window, still cant figure it out."

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

Forum statistics

Threads
1,215,220
Messages
6,123,694
Members
449,117
Latest member
Aaagu

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