+ Reply to Thread
Results 1 to 10 of 10

Extracting numbers from a string where they follow the letters "ps"

  1. #1
    Registered User
    Join Date
    09-04-2009
    Location
    Gloucestershire, England
    MS-Off Ver
    Excel 2010
    Posts
    45

    Question Extracting numbers from a string where they follow the letters "ps"

    I need to extract any numbers (0-9 only no symbols) that follow the letters "ps".
    "ps" could be in either upper or lower case or a mix of both. There may also be some hyphens or brackets between the ps and the numbers but no text. I need to extract just the numbers and only where there is no other text between the ps and the numbers. The ps could be anywhere in the text string and will not always be at the end of the string (although this will be the most common)
    Eg.
    C1464 PS25 - I want to extract the 25
    SUS680 H.PUMPS - I do not want to extract anything
    C1496 PS3 - I want to extract the 3
    U57119-p/s 12 - I want to extract the 12
    U57119 ps(13) - I want to extract the 13

    I assume that I would use Search to find the letter ps but I am unsure how to extract the numbers after that where there may be spaces or symbols and where the numbers may be 1 or 2 characters long.

    Thanks

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

    Re: Extracting numbers from a string where they follow the letters "ps"

    =iferror(abs(trim(right(substitute(upper(a1),"S",rept(" ",len(a1))),len(a1)))*1),"")
    Attached Files Attached Files
    Samba

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

  3. #3
    Registered User
    Join Date
    09-04-2009
    Location
    Gloucestershire, England
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Extracting numbers from a string where they follow the letters "ps"

    Quote Originally Posted by nflsales View Post
    =iferror(abs(trim(right(substitute(upper(a1),"S",rept(" ",len(a1))),len(a1)))*1),"")
    Hi Silva,
    Thank you for that. The only problem is where the cell only contains a number and no text. It is then giving me the number as the result when in fact I dont want anything if it is not preceeded with the PS text. Are you able to help with that?
    Thanks again

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

    Re: Extracting numbers from a string where they follow the letters "ps"

    =iferror(if(isnumber(a1),"",abs(trim(right(substitute(upper(a1),"S",rept(" ",len(a1))),len(a1)))*1)),"")

  5. #5
    Registered User
    Join Date
    09-04-2009
    Location
    Gloucestershire, England
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Extracting numbers from a string where they follow the letters "ps"

    Quote Originally Posted by nflsales View Post
    =iferror(if(isnumber(a1),"",abs(trim(right(substitute(upper(a1),"S",rept(" ",len(a1))),len(a1)))*1)),"")
    Hi Silva,
    Thank you for the new version, however this is still not working for me. I need the letter PS not just an S but if I change your "S" to "PS" and the a1's to B9, then I get no results at all even when I should.
    Sorry, not sure if I am being a bit thick here.

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

    Re: Extracting numbers from a string where they follow the letters "ps"

    Attach the sheet

  7. #7
    Registered User
    Join Date
    09-04-2009
    Location
    Gloucestershire, England
    MS-Off Ver
    Excel 2010
    Posts
    45

    Re: Extracting numbers from a string where they follow the letters "ps"

    Hi Silva,
    When I pasted in your formula a second time it worked except for a few records, but those particular records have extra letters between the ps and the numbers or have hyphens or slashes in them or in the ps e.g p/s. My managers have now decided that we will use the formula you have provided and do the few that don't work manually. Thank you for your help.

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

    Re: Extracting numbers from a string where they follow the letters "ps"

    If you provide data in excel we can resolve it

  9. #9
    Registered User
    Join Date
    05-10-2013
    Location
    Pomáz, Hungary
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: Extracting numbers from a string where they follow the letters "ps"

    Try this UDF:

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    08-05-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Extracting numbers from a string where they follow the letters "ps"

    Or this ...
    Please Login or Register  to view this content.

+ 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. Replies: 1
    Last Post: 08-15-2014, 06:00 AM
  2. Extracting Numbers from "4S, 2P, 8V" within a column.
    By tk357 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-01-2013, 05:42 PM
  3. Add letters to numbers in column "B"?
    By sem in forum Excel General
    Replies: 31
    Last Post: 03-03-2011, 07:11 AM
  4. Replies: 12
    Last Post: 07-14-2010, 10:39 AM
  5. Extracting Letters and Numbers in a random Alphanumeric String
    By rajbhar_s in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-03-2010, 08:07 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