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

1. ## 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. ## Re: Use LEFT formula to extract text preceding ONE OF TWO possible characters

Do "B" and "D" ever appear within the same cell?

3. ## 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

Alternate,

5. ## 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?

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

Originally Posted by dredwolf
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. ## Re: Use LEFT formula to extract text preceding ONE OF TWO possible characters

You are welcome

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

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

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}))

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

#### 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