+ Reply to Thread
Results 1 to 12 of 12

Extract numbers on the left in a string that also contains numbers on the right

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-09-2018
    Location
    Quebec, Canada
    MS-Off Ver
    Office 365
    Posts
    150

    Extract numbers on the left in a string that also contains numbers on the right

    Hello all,

    In this example, how to extract the reference on the left only:


    1069ANDRAA0013 expected: 1069
    A230ANDRAA0013 expected: A230
    14721ARSECA0181 expected: 14721
    W101HAKEZH5003 expected: W101

    Thank you very much in advance.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,703

    Re: Extract numbers on the left in a string that also contains numbers on the right

    Using Power Query

    Excel 2016 (Windows) 64 bit
    A
    B
    C
    2
    1069ANDRAA0013 1069
    3
    A230ANDRAA0013 A230
    4
    14721ARSECA0181 14721
    5
    W101HAKEZH5003 W101
    Sheet: Sheet1

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Split Column by Character Transition" = Table.SplitColumn(Source, "Column1", Splitter.SplitTextByCharacterTransition({"0".."9"}, (c) => not List.Contains({"0".."9"}, c)), {"Column1.1", "Column1.2"}),
        #"Removed Other Columns" = Table.SelectColumns(#"Split Column by Character Transition",{"Column1.1"})
    in
        #"Removed Other Columns"

    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.
    Attached Files Attached Files
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Extract numbers on the left in a string that also contains numbers on the right

    B1=LEFT(A1,SEARCH({"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"},A1,2)-1)

    This is an array formula.

    Close with CTRL+SHIFT+Enter.

    The brackets appear automaticly.
    Last edited by oeldere; 05-26-2022 at 02:43 PM. Reason: add A -Z
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  4. #4
    Forum Contributor
    Join Date
    10-09-2018
    Location
    Quebec, Canada
    MS-Off Ver
    Office 365
    Posts
    150

    Re: Extract numbers on the left in a string that also contains numbers on the right

    Thank you to both of you.

    Alan, I don't want to use Powerquery at the moment since it is not allowed for every user in my company.

    Oeldere, I tried your formula. It works for some rows and not for others. For example:

    with S115CARDGC0021, I get S115C but I should get S115
    with 14707CHEVSC0081, I get #VALUE! but I should get 14707
    with 14707DELIAD0011, I get 14707DELI but I should get 14707

    Is there any adjustment that we could make to the formula?

    Thank you again.

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,740

    Re: Extract numbers on the left in a string that also contains numbers on the right

    How about
    Formula: copy to clipboard
    =LEFT(A2,4+ISNUMBER(MID(A2,5,1)+0))

  6. #6
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Extract numbers on the left in a string that also contains numbers on the right

    Another approach.

    B1=IF(ISNUMBER(MID(A1,5,1)*1)=FALSE,LEFT(A1,4),LEFT(A1,5))

  7. #7
    Forum Contributor
    Join Date
    10-09-2018
    Location
    Quebec, Canada
    MS-Off Ver
    Office 365
    Posts
    150

    Re: Extract numbers on the left in a string that also contains numbers on the right

    Hi again oeldere and hello Fluff13!

    Both solutions give exactly the same results, with only one error left! We're almost there!! I really appreciate that you share some of your time with me.

    So among the 14K rows I have to work with, the last references that don't extract correctly are the ones like:

    NOVU320DUFOSD0101
    NOVU300FILTAF0011

    I should get NOVU320 or NOVU300 but both formulas give me NOVU3

    I could correct them manually but if one day new references appear with the same structure, I will not be able to extract them correctly. Is there any way to fix it?

    Thank you

  8. #8
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Extract numbers on the left in a string that also contains numbers on the right

    If you don't mind to use helper cells.

    B1
    =TRIM(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"0"," "),"1"," "),"2"," "),"3"," "),"4"," "),"5"," "),"6"," "),"7"," "),"8"," "),"9"," "))

    C1
    =LEFT(A1,FIND(MID(B1,IFERROR(FIND(" ",B1)+1,1),1000),A1)-1)

    Regards.
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    09-30-2019
    Location
    Chiangmai, Thailand
    MS-Off Ver
    Office 2016, Excel 2019
    Posts
    1,234

    Re: Extract numbers on the left in a string that also contains numbers on the right

    Another solution

    =LEFT(A1,AGGREGATE(15,6,ROW($A$1:$A$100)/(1/((CODE(MID(A1,ROW($A$1:$A$99),1))<=57)*(CODE(MID(A1,ROW($A$2:$A$100),1))>57))),1))

    it support case of
    14A707CHEVSC0081
    A14A404AHESS123

    Regards.

  10. #10
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,222

    Re: Extract numbers on the left in a string that also contains numbers on the right

    Try

    =LEFT(A2)&-LOOKUP(0,-MID(A2,2,{1,2,3,4,5}))

  11. #11
    Forum Guru
    Join Date
    02-27-2016
    Location
    Vietnam
    MS-Off Ver
    2024
    Posts
    6,175

    Re: Extract numbers on the left in a string that also contains numbers on the right

    Try this:

    =LEFT(A2,AGGREGATE(15,6,ROW($1:$10)/ISNUMBER(--MID(A2,ROW($1:$10),1))/ISERR(--MID(A2,ROW($2:$11),1)),1))

    A0069ANDRAA0013 result is: A0069

    NOVU320DUFOSD0101 result is: NOVU320

  12. #12
    Forum Contributor
    Join Date
    10-09-2018
    Location
    Quebec, Canada
    MS-Off Ver
    Office 365
    Posts
    150

    Re: Extract numbers on the left in a string that also contains numbers on the right

    Good morning all,

    I am really happy and relieved because Menem's and Phuocam's solutions work perfectly! You both make my day/week/month!

    Bo_ry's gives an error, but thank you anyway for your time.

    Thank you so much to all the helpers. Have a great day all.

    S.

+ 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 left numbers from text
    By sanjuss2 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-15-2020, 04:15 AM
  2. Extract all numbers from string, returning numbers to individual cells
    By LJBOS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-27-2020, 08:46 AM
  3. [SOLVED] Extract numbers from a the left and to the right of a string
    By T86157 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-09-2017, 10:38 AM
  4. Is there a formula that will extract the numbers to the left of the cell
    By benji1973 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 09-04-2015, 10:11 AM
  5. [SOLVED] Sum numbers left of a character from within a string
    By BarryTSL in forum Excel General
    Replies: 14
    Last Post: 04-17-2012, 01:11 PM
  6. Extract Data to right and left of numbers
    By chl in forum Excel General
    Replies: 1
    Last Post: 03-18-2010, 02:19 PM
  7. extract numbers with specific text from right or left
    By darkhangelsk in forum Excel General
    Replies: 2
    Last Post: 08-15-2009, 02:38 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