+ Reply to Thread
Results 1 to 8 of 8

Extract numbers of variable lengths from cell

  1. #1
    Registered User
    Join Date
    10-17-2013
    Location
    San Fransisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Extract numbers of variable lengths from cell

    Hey,

    I have a lot of data that looks like this:

    1979,410,1,0,"S2","0",1,,,1431939840,0

    1984,76,2,0,"S2","0",1,,,8667779072,0

    2003,76,2,0,"S2","11",1,,,46718346,0

    I want to extract the numbers after the ",,," but NOT include the last ",0" (for example 46718346 for 2003). I have tried to google an answer for some time now, but can't find an appropriate one so would really appreciate some help!

    Thanks!

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Extract numbers of variable lengths from cell

    Hi and welcome to the forum

    Assuming yoyr data is in A1, try this, copied down...
    =MID(A1,SEARCH(",,,",A1,1)+3,SEARCH("xx",SUBSTITUTE(A1,",","xx",10),1)-SEARCH("xx",SUBSTITUTE(A1,",,,","xx",1),1)-3)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    10-17-2013
    Location
    San Fransisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Extract numbers of variable lengths from cell

    Thanks, but I just get the #VALUE in return from Excel... I can copy paste some of my data in here:

    1983,76,1,0,"S2","0",1,,,1342739328,0
    1983,76,2,0,"S2","0",1,,,7436109824,0
    1983,152,1,0,"S2","0",1,,,406302528,0
    1983,152,2,0,"S2","0",1,,,702199424,0
    1983,410,1,0,"S2","0",1,,,1711859840,0

    and so on... It's the bold numbers I want.

    This is different values of exports and imports from different countries over time, so there isn't any direct patterns in the data. Except the ",,," and the ending ",0". So it's (almost) always different lengths of the numbers in the cells aswell...

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Extract numbers of variable lengths from cell

    try
    =TRIM(RIGHT(SUBSTITUTE(LEFT(A1,LEN(A1)-2),",",REPT(" ",25)),20))
    or
    =TRIM(RIGHT(SUBSTITUTE(LEFT(A1,LEN(A1)-2),",,,",REPT(" ",25)),20))
    or
    =SUBSTITUTE(MID(A1,FIND(",,,",A1)+3,255),",0","")
    Last edited by martindwilson; 10-17-2013 at 06:22 PM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Extract numbers of variable lengths from cell

    I used that on your sample data...
    A
    B
    26
    1979,410,1,0,"S2","0",1,,,1431939840,0 1431939840
    27
    1984,76,2,0,"S2","0",1,,,8667779072,0 8667779072
    28
    2003,76,2,0,"S2","11",1,,,46718346,0 46718346

    =MID(A26,SEARCH(",,,",A26,1)+3,SEARCH("xx",SUBSTITUTE(A26,",","xx",10),1)-SEARCH("xx",SUBSTITUTE(A26,",,,","xx",1),1)-3)

    But Martin's is shorter and easier

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

    Re: Extract numbers of variable lengths from cell

    try this
    =IFERROR(SUBSTITUTE(MID(A1,FIND(",,,",A1)+4,LEN(A1)),",0",),"")

  7. #7
    Registered User
    Join Date
    05-10-2013
    Location
    Pomáz, Hungary
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: Extract numbers of variable lengths from cell

    ... Or try to replace *,,, with nothing.

  8. #8
    Registered User
    Join Date
    10-17-2013
    Location
    San Fransisco, CA
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Extract numbers of variable lengths from cell

    Thank you so much!

+ 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. [SOLVED] Extracting Text From Cells of Variable Lengths
    By stinkstik in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 04-25-2013, 02:46 PM
  2. [SOLVED] Unable to pull numbers (variable lengths and periods) out of cells
    By BDavis in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-08-2013, 04:02 PM
  3. Multiple named ranges with variable lengths set by user via single cell value
    By devcow in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2012, 01:12 AM
  4. Replies: 3
    Last Post: 05-09-2012, 11:36 AM
  5. [SOLVED] Parsing data of variable lengths
    By JP Romano in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-02-2011, 04:54 PM

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