+ Reply to Thread
Results 1 to 6 of 6

How to find number at end of a cell

  1. #1
    Registered User
    Join Date
    08-01-2012
    Location
    United Kingdom
    MS-Off Ver
    Office 2010
    Posts
    71

    How to find number at end of a cell

    Hi

    I have a column which lists companies and their ID number in the form "Company name - ID 4892"

    Is there a way to reference this cell so I just get the number at the end? I did use =RIGHT(A2,4) but that doesn't work when there is a 3 or 5 digit code.

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,719

    Re: How to find number at end of a cell

    For up to 5 digits try

    =LOOKUP(10^5,RIGHT(A2,{1,2,3,4,5})+0)
    Audere est facere

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,415

    Re: How to find number at end of a cell

    If you always have "ID " in front of the number, try:

    =RIGHT(A1,LEN(A1)-FIND("ID ",A1)-2)


    Regards, TMS


    Edit: to return a numeric result, use:

    =--RIGHT(A1,LEN(A1)-FIND("ID ",A1)-2)
    Last edited by TMS; 01-12-2013 at 11:10 AM.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


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

    Re: How to find number at end of a cell

    try it
    =--SUBSTITUTE(A1,"ID"," ")

  5. #5
    Registered User
    Join Date
    08-01-2012
    Location
    United Kingdom
    MS-Off Ver
    Office 2010
    Posts
    71

    Re: How to find number at end of a cell

    Quote Originally Posted by daddylonglegs View Post
    For up to 5 digits try

    =LOOKUP(10^5,RIGHT(A2,{1,2,3,4,5})+0)
    Quote Originally Posted by TMShucks View Post
    If you always have "ID " in front of the number, try:

    =RIGHT(A1,LEN(A1)-FIND("ID ",A1)-2)


    Regards, TMS


    Edit: to return a numeric result, use:

    =--RIGHT(A1,LEN(A1)-FIND("ID ",A1)-2)
    Quote Originally Posted by Ghozi Alkatiri View Post
    try it
    =--SUBSTITUTE(A1,"ID"," ")
    Thanks - the first two work, the last one doesn't since there's also the company name at the start of the cell (get rid of that and its fine though).

    I don't understand how the first one works but it does. Thanks for letting me know about the -- thing too, I'd never seen that before.

  6. #6
    Forum Contributor
    Join Date
    12-23-2003
    Posts
    179

    Re: How to find number at end of a cell

    Quote Originally Posted by davidman1 View Post
    Hi

    I have a column which lists companies and their ID number in the form "Company name - ID 4892"

    Is there a way to reference this cell so I just get the number at the end? I did use =RIGHT(A2,4) but that doesn't work when there is a 3 or 5 digit code.
    1.

    =REPLACE(A2,1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A2&"0123456789"))-1,"")+0

    2.

    =LOOKUP(9.99999999999999E+307,--RIGHT(A2,ROW(INDIRECT("1:"&LEN(A2)))))

    For more on 9.99... and its role in the LOOKUp expression:

    http://tinyurl.com/alpxzho
    http://tinyurl.com/bbt2ant

    3.

    =TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",LEN(A2))),LEN(A2)))+0

    4. An old one...

    =RIGHT(A2,SUMPRODUCT((LEN(A2)-LEN(SUBSTITUTE(A2,{0,1,2,3,4,5,6,7,8,9},"")))))+0

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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