+ Reply to Thread
Results 1 to 8 of 8

Extracting first set of numbers of variable length from a string

  1. #1
    Registered User
    Join Date
    02-03-2014
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Extracting first set of numbers of variable length from a string

    Hi,

    I have thousands of references and I need the first set of numbers from the reference but unfortunately some contain letters and some are of different lengths

    REF-50789-LYD-12. (I need 50789 only)
    REF-4089D-LYD-125 (I need 4089 only)
    REF-23400-LYD-345 (I need 23400 only)

    It will always lie between the first set of '-' but will be of varying lengths and i need the numbers only.

    Is this possible? I'm.struggling to do this with just the MID function. Extremely.grateful for any help-thanks

  2. #2
    Registered User
    Join Date
    09-24-2015
    Location
    Delhi, India
    MS-Off Ver
    MS Office 2013
    Posts
    65

    Re: Extracting first set of numbers of variable length from a string

    hi Lydyth,

    =MID(K5,(FIND("-",K5)+1),FIND("-",SUBSTITUTE(K5,"-","@",1))-(FIND("-",K5)+1))
    Use this

    Thanks
    Rohit

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Extracting first set of numbers of variable length from a string

    Or this UDF

  4. #4
    Registered User
    Join Date
    02-03-2014
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Extracting first set of numbers of variable length from a string

    Thanks rohit, that works for variable length but still seems to pull through letters

    So ref-56749d-LYD-123 ( gives me 56749d instead of 56749)

    Also thanks pepe, but long story short I need to resolve with formula if possible rather than vba.

    Appreciate everyone's help.:D

  5. #5
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,914

    Re: Extracting first set of numbers of variable length from a string

    =LOOKUP(99^99,MID(A1,5,ROW(INDIRECT("1:25")))+0)
    Please Login or Register  to view this content.
    try this
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  6. #6
    Registered User
    Join Date
    02-03-2014
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    5

    Re: Extracting first set of numbers of variable length from a string

    Wow thank you thats perfect.

    I may be pushing my luck but if possible can you explain what that is doing? I'm just trying to learn as much as I can. I recognise all of the functions used, just struggling to break it down. If not thanks anyway as that seems to have worked very well!

  7. #7
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Extracting first set of numbers of variable length from a string

    =MID(A1;5;MATCH(TRUE;ISERROR(1*MID(A1;ROW(INDIRECT("5:25"));1));0)-1)*1 entered as an array formula also works.

    The best way to see what it does is to use the " Evaluate formula" tool

  8. #8
    Registered User
    Join Date
    09-24-2015
    Location
    Delhi, India
    MS-Off Ver
    MS Office 2013
    Posts
    65

    Re: Extracting first set of numbers of variable length from a string

    Hi Lydyth,

    you can try this.

    =LOOKUP(99^99,MID(A14,MIN(IFERROR(FIND({1;2;3;4;5;6;7;8;9;0},A14),"")),ROW(INDIRECT("1:25")))+0)

    Thanks
    Rohit

+ 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] Need help extracting values from variable length results
    By hkshwa in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-18-2013, 09:22 PM
  2. Replies: 1
    Last Post: 01-22-2013, 03:45 PM
  3. Replies: 3
    Last Post: 11-21-2012, 03:28 PM
  4. [SOLVED] Extracting Text from a string of Text & Digits of variable length
    By hastex in forum Excel General
    Replies: 6
    Last Post: 06-06-2012, 09:11 AM
  5. Extracting a number from a string that varies in length...
    By lucraft in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-01-2012, 11:30 AM
  6. Extracting numbers of varying length from a string
    By bethj in forum Excel General
    Replies: 3
    Last Post: 12-13-2011, 06:03 AM
  7. Extracting variable length data from a cell
    By nuttlys in forum Excel General
    Replies: 2
    Last Post: 07-08-2010, 10:22 AM

Tags for this Thread

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