+ Reply to Thread
Results 1 to 9 of 9

Help with extracting second last number from string

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Help with extracting second last number from string

    Hi

    I have a list of numbers that vary in length and also contain the letter "x" in some of them like this:

    0x60
    1313
    0x41
    x254
    123x
    1
    9x73
    00x9
    522x
    335
    x39x
    34


    And so on. I need to do 3 things:

    1. Extract the last number only if it is a "1". If it is an "x", then I need to extract the second last number.
    2. Extract the last number if it equals 1,2 or 3. If it is an "x", then I need to extract the second last number.
    3. Extract the last number if there is an occurrence of 1 in the last 3. If there is only 1 or 2 numbers in the cell, then look for an occurrence of 1 in these and extract the last number.

    Can anyone assist me with this please?

    Thanks
    Last edited by maym; 12-12-2017 at 08:40 PM.

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

    Re: Help with extracting second last number from string

    Quote Originally Posted by maym View Post
    Hi
    0x60
    1313
    0x41
    x254
    123x
    1
    9x73
    00x9
    522x
    335
    x39x
    34
    What exactly your desired results of above list, one by one?
    Quang PT

  3. #3
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Help with extracting second last number from string

    sorry should have included that.

    Sample attached.
    Attached Files Attached Files

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

    Re: Help with extracting second last number from string

    Try in B2:
    =IF(RIGHT(SUBSTITUTE(A2,"x",""))+0=1,1,"")
    C2:
    =IF(OR(RIGHT(SUBSTITUTE(A2,"x",""))+0={1,2,3}),RIGHT(SUBSTITUTE(A2,"x",""))+0,"")
    D2:
    =IF(ISNUMBER(SEARCH(1,RIGHT(A2,3))),1,"")
    Drag all down
    There is slightly difference with 1 in A7: 2nd result is 1 (your derived result for 2nd result is nothing)

  5. #5
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Help with extracting second last number from string

    ok great, thanks! I'll give it a go and report back

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

    Re: Help with extracting second last number from string

    Could you clarify this:
    123x -->D6: second result: 2
    9x73-->D8: second result : 2

  7. #7
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Help with extracting second last number from string

    thank you so much!

    For 3rd result for A6 (in cell D6), I get nothing. However there was an occurrence of 1 in the last 3 (even though it was before the x) so I should get a 1 here?

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

    Re: Help with extracting second last number from string

    Quote Originally Posted by maym View Post
    thank you so much!

    For 3rd result for A6 (in cell D6), I get nothing. However there was an occurrence of 1 in the last 3 (even though it was before the x) so I should get a 1 here?
    Use:
    =IF(ISNUMBER(SEARCH(1,RIGHT(SUBSTITUTE(A2,"x",""),3))),1,"")

    Note that with this, after "x" is moved out, 1 is in last 3 digits then
    1x39x --> 3rd = 1

  9. #9
    Forum Contributor
    Join Date
    10-12-2011
    Location
    Sydney
    MS-Off Ver
    Excel 2016 in 2024
    Posts
    857

    Re: Help with extracting second last number from string

    sorry, both of those should be a 3 as the result (typo).

+ 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. Extracting first number from the right of string
    By hotwax in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-31-2014, 04:01 AM
  2. [SOLVED] Extracting a number from a string
    By cool_anu4u in forum Excel General
    Replies: 1
    Last Post: 10-17-2013, 05:24 AM
  3. [SOLVED] Extracting A Number From A String Of Text
    By @MeDaveT in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-15-2013, 02:57 PM
  4. Replies: 12
    Last Post: 03-20-2013, 05:46 PM
  5. Extracting the nth number from an alphanumeric string
    By Chinchin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-15-2011, 02:38 PM
  6. Extracting a number from a string
    By SgtSunshine in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-25-2010, 07:33 AM
  7. Extracting a number from a string
    By dsexpress in forum Excel General
    Replies: 3
    Last Post: 04-26-2008, 08:41 AM
  8. Extracting a number in a text string
    By Pogo in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-17-2006, 01:45 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