+ Reply to Thread
Results 1 to 13 of 13

Formula to copy only numbers from a text/number column

  1. #1
    Registered User
    Join Date
    10-31-2013
    Location
    panama
    MS-Off Ver
    Excel 2010
    Posts
    3

    Formula to copy only numbers from a text/number column

    Text
    A7b12 890c(d.e 123456
    A7b12 890c(d.e:123456
    A7b12 890c(d.e 12345
    A7b12 890c(d.e:12345

    123456 a7b12 890c(d.e
    123456:a7b12 890c(d.e
    12345 a7b12 890c(d.e
    12345:a7b12 890c(d.e

    A7b12 890c(d.e 123456 a7b12 890c(d.e
    A7b12 890c(d.e:123456:a7b12 890c(d.e
    A7b12 890c(d.e 12345 a7b12 890c(d.e
    A7b12 890c(d.e:12345:a7b12 890c(d.e

    12345
    12345:
    123456
    A7b12890c(d.e:12345:a7b12890c(d.e
    A7b12890c(d.e:123456:a7b12890c(d.e

    I need a formula that can unify all of the above cases and copy a random 5- or 6-digit number from the Text column to another Number column. The catch is that these numbers might be in different positions and be preceeded or continued not only by letters and symbols but by other numbers of 1-,2-,3-,4-,7- and 8-digit numbers. However it is not a 100% defined where the numbers are positioned and if they are preceeded ot continued at all. The 5- and 6- digit numbers that are to be copied are 12345 and 123456 respectively.
    * I need one formula because the list I need it for is around 30 000 entries long.

  2. #2
    Forum Contributor
    Join Date
    03-21-2013
    Location
    Corvallis, OR
    MS-Off Ver
    Excel 2010
    Posts
    174

    Re: Formula to copy only numbers from a text/number column

    There needs to be something consistent to find the number's position within the string. The number itself can be that consistency, but I'm not sure by your post if that is the case. If it is the case, then the two numbers you've listed (12345, and 123456) can be pulled out of the strings with the following formula if they exist:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    If your numbers are in cells, replaced the "123456" with the cell address. If the numbers definitely always exist, the formula can be shortened by removing some of the IF statements and just using
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by bmxfreedom; 11-06-2013 at 10:47 AM.

  3. #3
    Registered User
    Join Date
    10-31-2013
    Location
    panama
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Formula to copy only numbers from a text/number column

    No, unfortunately it is not a static number. It is always different and might be in a different position, but it is always the 5- or 6- digit number in the row that needs to be copied.

    example: "42asdasd 467305" where 467305 needs to be copied
    or "asdoh423489 asfgdjnk" where 423489 needs to be copied
    or "skg 96823klk 3231" where 96823 needs to be copied
    Last edited by rockvibe; 11-08-2013 at 05:17 AM.

  4. #4
    Valued Forum Contributor
    Join Date
    10-29-2012
    Location
    Mojokerto,Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    554

    Re: Formula to copy only numbers from a text/number column

    =if(isnumber(find(123456,a1)),123456,if(isnumber(find(12345,a1)),12345))

  5. #5
    Registered User
    Join Date
    10-31-2013
    Location
    panama
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Formula to copy only numbers from a text/number column

    As stated above this formula will not work because the number to be extracted is not always static but variable in each row. The only constant for the number is its 5- and 6-digit nature.

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Formula to copy only numbers from a text/number column

    I think you'll need a UDF. You might want to ask the moderators to move this to the programming folder.
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  7. #7
    Forum Contributor
    Join Date
    03-21-2013
    Location
    Corvallis, OR
    MS-Off Ver
    Excel 2010
    Posts
    174

    Re: Formula to copy only numbers from a text/number column

    You mentioned that the number of characters in each number string is always 5 or 6, but there are sometimes 8 character number strings preceding or following them. Did you mean following directly, or following after a space or other text? i.e., if the number your looking for is 467305 is included in a string that looks like 42asdasd 467305 12345678, my original formula will still work so long as you can define the number being found in this case 467305.
    If the 5 or 6 digit number is a total unknown (other than the fact that it exists within the string), you may need to apply nested if statements that search for any 5 or 6 digit number within the string by using iserror(mid(string,1,6)*1) and iserror(mid(string,1,5)*1), then returning the first result when this is false. This would only work if the potential 8 digit numbers you speak of are always after the value you are searching for.

  8. #8
    Forum Contributor
    Join Date
    03-21-2013
    Location
    Corvallis, OR
    MS-Off Ver
    Excel 2010
    Posts
    174

    Re: Formula to copy only numbers from a text/number column

    It might be even easier to understand, or to write a formula, if you split the string up by groups of 6 then 5 for each character that exists. This would require a lengthy series of formulas though...

  9. #9
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Formula to copy only numbers from a text/number column

    I also think that to get the results you looking for can only be done by using UDF (User Defined Function)

    I think this code will work for you. It 12345 and 12346

    To open VB editor press and hold ALT then press F11. Click Insert and select Module. Paste code into the module and close VB editor.

    No use formula =NumberOut(A1) and drag it down

    Please Login or Register  to view this content.
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  10. #10
    Forum Contributor
    Join Date
    03-21-2013
    Location
    Corvallis, OR
    MS-Off Ver
    Excel 2010
    Posts
    174

    Re: Formula to copy only numbers from a text/number column

    Here's a macro that will loop through the possible position based search formulas for each cell in column a, and return the first resulting formula that results in a 6 or 5 digit number string in column B. It takes 32 seconds on my system to write unique formulas for each of the 30,000 rows of your text duplicated to fill the column.
    Please Login or Register  to view this content.
    I've attached a copy of the workbook so you can try it out.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    03-21-2013
    Location
    Corvallis, OR
    MS-Off Ver
    Excel 2010
    Posts
    174

    Re: Formula to copy only numbers from a text/number column

    Range("D2").Value = Now()
    That part of the code can be removed, along with the associated cells in column D. They're just there as a time measuring method.

    Also, "Sheet1" would need to be changed to whatever the actual sheet is named, and all instances of "B" & curRow or "B" & r would need to be changed to reflect the column you wish to have the formulas present in; say column C instead of B, then it would be "C" & curRow and "C" & r.
    Last edited by bmxfreedom; 11-08-2013 at 03:49 PM. Reason: explaining a bit more about possible adjustments to the code.

  12. #12
    Forum Contributor
    Join Date
    03-21-2013
    Location
    Corvallis, OR
    MS-Off Ver
    Excel 2010
    Posts
    174

    Re: Formula to copy only numbers from a text/number column

    The problem with the UDF method is that it is very processor intensive. With 30,000 rows of data, it will take about 15 seconds to recalculate your workbook anytime you need to. The formula creation method takes longer at first, but after the formulas are written, they are much faster to calculate. (under a second for all 30,000). The formula creation method can also be limited to a single cell at a time if you want (similar to the UDF) by removing the double loop and just using:
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    03-21-2013
    Location
    Corvallis, OR
    MS-Off Ver
    Excel 2010
    Posts
    174

    Re: Formula to copy only numbers from a text/number column

    I just noticed that the UDF function here doesn't return the value 12890 in the string "A7b12890c(d.e:123456:a7b12890c(d.e ", where my formula creation method does. This brings the question, which 5 or 6 character number do you want out of this string? If you change the 123456 in this string to something that is not 5 or 6 digits, the UDF fails to pick up the other 5 digit number; 12890...
    AlKey, I'm hoping to understand this UDF better. How does it determine that the middle 5 or 6 digit number set in this scenario is the only one to return, while in other strings, it returns the same characters if they appear at the beginning or the end of the string?
    RockVibe, can you shed some light on this question?
    AlKey, this is a fascinating function. I would love to know more about it if you have the time.
    Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 4
    Last Post: 08-03-2013, 04:08 AM
  2. [SOLVED] Need a column of numbers based on text & number entries
    By prssmzk in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 01-24-2013, 11:10 PM
  3. Replies: 5
    Last Post: 12-29-2008, 05:48 PM
  4. Replies: 1
    Last Post: 04-15-2008, 01:59 AM
  5. extract number and use in formula from text & numbers in cell
    By ivory_kitten in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-14-2006, 12:45 AM

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