Closed Thread
Results 1 to 13 of 13

Extract & Copy a phone number from text

  1. #1
    Registered User
    Join Date
    08-25-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Extract & Copy a phone number from text

    I have hundreds of rows in excel with lots of numbers in between, the only pattern there is that alsmost all cells have a 10 digit number. Is it possible to write some vba that will extract and paste 10 digit number on the cell next to it?


    These would be some samples;

    The number found on this customer's account is 8055555555 along with the account #...
    The VM number on account 123465 was changed recently to 8661234567 due to an order error…
    At 0800 we received another call from 2523691234 regarding account 123456.

    There are multiple numbers in the text, on each row, but I need to only extract and copy to next cell the ones that are 10 digits.

    Thanks!
    Last edited by alpha.martinez; 08-25-2010 at 02:52 PM.

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Extract & Copy a phone number from text

    Please give some sample data that covers all possibilities.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Extract & Copy a phone number from text

    Try this

    =MID(A2,FIND(MID(A2,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A2&"0123456789")),1),A2,1),10)

    This will return 10 characters beginning with the first number in the string, it should be okay provided your strings contain exactly 10 consecutive numbers (blanks included).

    Hope this helps
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  4. #4
    Registered User
    Join Date
    08-25-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Extract & Copy a phone number from text

    The problem here is that we have multiple numbers within same string of text. Some are account numbers that are only 6 digits and some are other numbers, the 10 digit number I want to extract is not always the first number to the LEFT, RIGHT or MID, it is in random order.

    The formula finds some the number I need only when it is the first set of numbers in the text string.

  5. #5
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Extract & Copy a phone number from text

    As NVBC says post a sample workbook showing the range of data you are trying to handle.

    The formula given was just a shot in the dark!

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Extract & Copy a phone number from text

    If you install a free addin from here: Morefunc.

    Then you can apply formula:

    =REGEX.MID(A2,"\d{10}")

    copied down.

    Seems to work on the samples you provided.
    Last edited by NBVC; 08-25-2010 at 03:30 PM. Reason: Edited formula from =REGEX.MID(A2,"\d{10}",1,FALSE) the 1,FALSE isn't needed

  7. #7
    Registered User
    Join Date
    08-25-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Extract & Copy a phone number from text

    The reason why I provided only the samples above is due to the data I'm working is got a high level of privacy due to it reveals customer's information from the company I work for.

    I have replicated the data and uploaded a sample that resembles the data I am working with.

    Thank you!
    Attached Files Attached Files

  8. #8
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Extract & Copy a phone number from text

    I just tested my formula with the addin in your attachment.. and it worked for every one of them.

  9. #9
    Registered User
    Join Date
    08-25-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Extract & Copy a phone number from text

    It did work for all thank you!, Would you be able to also provide a VBA solution for this, I'd like to apply this without having to install something on all computers. We have multiple users who will need some type of macro that will enable them to do this on their computer.

  10. #10
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Extract & Copy a phone number from text

    That addin is supposed to have a feature that allows you to embed it in the wrokbork for sharing... It wasn't working at one point, but not sure if it is fixed now....

    But unfortunately not I for the VBA version, that is not my expertise... I know there are others here who know how to do the regex functions with VBA... one will hopefully come by (or produce an alternative VBA function).

  11. #11
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Extract & Copy a phone number from text

    Ok, I just stole this from here: http://www.ozgrid.com/forum/showthre...t=37624&page=1 with credit to Richie(UK)


    and adjusted it... and it seemed to work:

    Please Login or Register  to view this content.
    Then Apply function =RE10(A2) and copy down
    Last edited by NBVC; 08-26-2010 at 08:36 AM. Reason: typo

  12. #12
    Registered User
    Join Date
    06-02-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    1

    Re: Extract & Copy a phone number from text

    Quote Originally Posted by NBVC View Post
    Ok, I just stole this from here: http://www.ozgrid.com/forum/showthre...t=37624&page=1 with credit to Richie(UK)


    and adjusted it... and it seemed to work:

    Please Login or Register  to view this content.
    Then Apply function =RE10(A2) and copy down

    Hello there,

    Many thanks for your help.
    But I m stuck here, I used ur function as described by u and it worked fine for the first time, but when I exited the Excel 2007 and again opened the file and tried to extract the numbers from text, it didn't work. Then I again created a new module in Excel VBA and the tried to execute it. But this time it showed no result for cellphone numbers, instead it showed "#REF!"
    Could you please help me in getting this function again working for me?
    I am attaching the excel file.

    Many many thanks in advance.
    Attached Files Attached Files

  13. #13
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Extract & Copy a phone number from text

    Anurag,

    Welcome to the Forum, unfortunately:

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread. It makes sense to have a new thread for your question because a thread with numerous replies can be off putting & difficult to pick out relevant replies.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1