+ Reply to Thread
Results 1 to 5 of 5

Need help returning a specific number of characters from a variable string

  1. #1
    Registered User
    Join Date
    06-04-2014
    Posts
    4

    Need help returning a specific number of characters from a variable string

    Hi guys,

    If for example, I have a set of IDs like:

    Bellen-234-B25R
    Carlota-345-C20RDF
    Quad-765-Q20LP

    How would I return just the first 4 characters after the second dash? The closest I can get is ALL the characters after the second dash.

    Thanks.

  2. #2
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Need help returning a specific number of characters from a variable string

    Try this

    =LEFT(TRIM(RIGHT(SUBSTITUTE(A1,"-",REPT(" ",255)),255)),4)

    A
    B
    1
    Bellen-234-B25R B25R
    2
    Carlota-345-C20RDF C20R
    3
    Quad-765-Q20LP Q20L
    If you like my answer please click on * Add Reputation
    Don't forget to mark threads as "Solved" if your problem has been resolved

    "Nothing is so firmly believed as what we least know."
    --Michel de Montaigne

  3. #3
    Forum Expert azumi's Avatar
    Join Date
    12-10-2012
    Location
    YK, Indonesia
    MS-Off Ver
    Excel 2019
    Posts
    2,366

    Re: Need help returning a specific number of characters from a variable string

    Maybe:

    =LEFT(RIGHT(A1,LEN(A1)-SEARCH("-",A1,SEARCH("-",A1,1)+1)),4)

  4. #4
    Registered User
    Join Date
    06-04-2014
    Posts
    4

    Re: Need help returning a specific number of characters from a variable string

    Yep, both of those seem to work perfectly.
    Thanks guys.

  5. #5
    Forum Guru AlKey's Avatar
    Join Date
    07-20-2009
    Location
    Lakeland, FL USA
    MS-Off Ver
    Microsoft Office 2010/ Office 365
    Posts
    8,903

    Re: Need help returning a specific number of characters from a variable string

    Thank you for the feedback!
    Last edited by AlKey; 06-04-2014 at 04:18 PM.

+ 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. Returning Characters From A String
    By Solarissf in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-22-2006, 04:06 PM
  2. [SOLVED] Special characters in a string variable
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2006, 03:40 PM
  3. [SOLVED] How do I find a specific characters position in a string variable
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-11-2006, 10:30 AM
  4. Pass multiple characters to a string variable
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-19-2005, 06:26 AM
  5. [SOLVED] trim a string by specific number of characters
    By windyoldman in forum Excel General
    Replies: 2
    Last Post: 07-13-2005, 09:05 AM

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