+ Reply to Thread
Results 1 to 11 of 11

Finding 6 digit numbers in a text string

  1. #1
    Registered User
    Join Date
    11-25-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    6

    Finding 6 digit numbers in a text string

    Hi folks,

    This is my first post here on the forum.

    Ok so I have a banking dataset with a 'description' field containing a random text string , in this string there is a 6 digit customer reference number Im trying to extract.

    This 6 digit ref always has leading number 2, 3 or 4 and is USUALLY preceded by letters "ECN" (not always). It can appear anywhere in the string and can appear twice.

    So it can look like
    ECN412345
    ECN 412345
    ECN:412345
    412345
    etc

    Examples of text string formats

    BLAH UK LTD /RFB/ECN412345
    B/O BLAH 1234/ECN412345 E2EID/NOTPROVIDED ECN412345
    BLAH.COM 412345 44023345273216000N BLAH.COM 412345
    BLAH TRAVEL LIMITED (NORTH /RFB/ECN:412345 BLAH TRAVEL
    ECN412345
    412345
    etc

    PS I found a useful formula on another thread ,
    http://www.excelforum.com/excel-gene...xt-string.html

    Ive tweaked it for 6 digits and it works but not in all scenarios

    where A1 is text string cell,
    =TEXT(LOOKUP(10^8,MID(SUBSTITUTE(A1," ","x"),ROW(INDIRECT("1:"&LEN(A1)-5)),6)+0),"000000")

    All help appreciated thanks
    N.

  2. #2
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Finding 6 digit numbers in a text string

    With A1 contains text

    In B1:

    Please Login or Register  to view this content.
    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer. Press F2 on that cell and try again.
    Quang PT

  3. #3
    Registered User
    Join Date
    11-25-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    6

    Re: Finding 6 digit numbers in a text string

    Thank you bebo Works perfectly

    Would you mind giving me a brief 'logic' to how the formula works? Id like to improve my understanding also .
    If its too complicated no worries but would be great

  4. #4
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Finding 6 digit numbers in a text string

    For example, "123456" is targeted in string

    In general,
    I tried to convert it to " 123456 " (six digits with space prior and after):
    taking into account:

    "ECN123456" => " 123456 "
    ":123456" => " 123456 "
    and not taking into account: "1234567"

    then go through each 8 digits in string, to search for "space_6 digits_space" sub-string.

    Hope it is clear for you.

  5. #5
    Registered User
    Join Date
    11-25-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    6

    Re: Finding 6 digit numbers in a text string

    Ah ok I think I understand now. Very good way to solve it.

    Thanks again

  6. #6
    Registered User
    Join Date
    11-25-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    6

    Re: Finding 6 digit numbers in a text string

    Ok slight problem Ive noticed that where there is TWO 6 digit numbers in the string
    the formula will return the first one as the result ...even if it doesnt have 'ECN' preceding text..

    e.g.
    Text String= 453881 ECN305080 NONREF
    Formula result= 453881

    I need the result to be 305080 in this case as it is the actual ECN Im looking for
    ...the other is a bank sort code I dont need.
    Complicated I know...

    Can the formula be amended to look for prefix "ECN" as first preference for result ...and IF this doesnt appear in string then take remaining 6 digit number beginning with 2,3 or 4?

    Complicated I know...

  7. #7
    Registered User
    Join Date
    11-25-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    6

    Re: Finding 6 digit numbers in a text string

    So first preference
    ECN123456 or ECN 123456 or ECN:123456
    If not found
    second preference
    123456

    Apologies I should have made this a requirement in my initial question.

  8. #8
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Finding 6 digit numbers in a text string

    OK. Now 1st priority is searching "ECN:", 2nd is for "ECN", then main formula with this syntax:
    =IFERROR(MID(A1,IFERROR(SEARCH("ECN:",A1)+4,SEARCH("ECN",A1)+3),6),main formula)

    Please Login or Register  to view this content.

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

    Re: Finding 6 digit numbers in a text string

    Or can try below formula
    =iferror(right(mid(a1,search("ecn",a1),search(" ",a1,search("ecn",a1)+6)-search("ecn",a1)),6),lookup(99^99,(mid(" "&a1&" ",row(indirect("1:"&len(a1))),8)+0)/((mid(" "&a1&" ",row(indirect("1:"&len(a1))),8)+0>199999)*(mid(" "&a1&" ",row(indirect("1:"&len(a1))),8)+0<500000))))
    Please Login or Register  to view this content.
    Samba

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

  10. #10
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Finding 6 digit numbers in a text string

    Or this:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Dave

  11. #11
    Registered User
    Join Date
    11-25-2015
    Location
    Melbourne, Australia
    MS-Off Ver
    2013
    Posts
    6

    Re: Finding 6 digit numbers in a text string

    Thanks to all !
    -N

+ 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] extract 10 digit number only from text string
    By visha_1984 in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 02-06-2015, 09:42 AM
  2. instances of a single digit in a string of numbers
    By rockchalk313 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-19-2014, 08:32 AM
  3. [SOLVED] Finding numbers in text string
    By Henry c in forum Excel General
    Replies: 11
    Last Post: 02-17-2014, 07:30 AM
  4. Finding numbers in a text string
    By HarvardMajesty in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-25-2013, 01:56 PM
  5. Retrieving 3 and 5 Digit Numbers from a Text String
    By AntiVirus2011 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-23-2012, 01:08 PM
  6. [SOLVED] macro to extract 9 digit numbers as well as alpha numberic 9 digit numbers from txt file
    By Raju Radhakrishnan in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2012, 10:15 AM
  7. [SOLVED] Return a digit in a string of numbers
    By W M in forum Excel General
    Replies: 5
    Last Post: 05-11-2005, 02:06 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