+ Reply to Thread
Results 1 to 8 of 8

Use LEFT formula to extract text preceding ONE OF TWO possible characters

  1. #1
    Registered User
    Join Date
    11-01-2009
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    33

    Use LEFT formula to extract text preceding ONE OF TWO possible characters

    Hi all, I am trying to use a Left formula to extract the first several characters of a variable string. A few examples of these values will be:

    20B1
    20B2
    20B3
    21B1
    21D2
    21D43
    101B1
    101B2
    101D3

    I want to determine the numbers preceding the first letter (only the letters "B" and "D" are used) but number of preceding characters varies.

    Assuming my data is in A column, I am trying to use something like this formula: =LEFT(A1,FIND("B",A1)-1) to return the numbers before the "B" (e.g. "20", "21", and "101").

    This works perfectly, except for the fact that my cell values contain both the letter "B" AND the letter "D" and I need to find the values for all cells.

    Is there any way of doing something like =LEFT(A1,FIND("B" or "D",A1)-1) or something that could return the numbers preceding the first alphabetical character...?

    Thanks!

  2. #2
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Use LEFT formula to extract text preceding ONE OF TWO possible characters

    Do "B" and "D" ever appear within the same cell?
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  3. #3
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Use LEFT formula to extract text preceding ONE OF TWO possible characters

    If not, try one of these 2:
    =IF(ISERROR(FIND("B",A1)),LEFT(A1,FIND("D",A1)-1),LEFT(A1,FIND("B",A1)-1))
    or, since you have 2010 excel
    =IFERROR(LEFT(A1,FIND("B",A1)-1),LEFT(A1,FIND("D",A1)-1))

    Hope this helps

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Use LEFT formula to extract text preceding ONE OF TWO possible characters

    Alternate,
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Use LEFT formula to extract text preceding ONE OF TWO possible characters

    What is the maximum number of digits that will precede the letter?

    Do any of the strings start with leading zeros?
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  6. #6
    Registered User
    Join Date
    11-01-2009
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    33

    Re: Use LEFT formula to extract text preceding ONE OF TWO possible characters

    Quote Originally Posted by dredwolf View Post
    If not, try one of these 2:
    =IF(ISERROR(FIND("B",A1)),LEFT(A1,FIND("D",A1)-1),LEFT(A1,FIND("B",A1)-1))
    or, since you have 2010 excel
    =IFERROR(LEFT(A1,FIND("B",A1)-1),LEFT(A1,FIND("D",A1)-1))

    Hope this helps
    Each cell contains either "B" or "D".

    The second formula worked like a charm. Thanks!

  7. #7
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: Use LEFT formula to extract text preceding ONE OF TWO possible characters

    You are welcome

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Use LEFT formula to extract text preceding ONE OF TWO possible characters

    Quote Originally Posted by Tony Valko View Post
    What is the maximum number of digits that will precede the letter?

    Do any of the strings start with leading zeros?
    Just for the academic exercise...

    Let's assume that the max number of digits will be 3 and there are no leading zeros.

    =LOOKUP(1000,--LEFT(A2,{1,2,3}))

+ 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