Formula Extract Characters at the Beginning of a String

gonesalsa

New Member
Joined
May 5, 2014
Messages
7
Hello
I need to extract the numbers at the beginning of a string. The problem is that there could 1, 2 or 3 digits. Here are examples of the string:

4JXXXXXXXXX1204
10EXXXXXXXXX1204
127JXXXXXXXXX1204

I only want to extract the 4, 10 and the 127 in the above strings. I tried =LEFT(B1,LEN(B1)-14), but the formula isn't working on the last string where the number is 3 digits. it only pulls 12, instead of 127.

Thanks
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Now look at my post # 9 .. I expressed the opinion that we should be careful with more than 3 digits. This means that we know something about our data (first post, examples)
But for a maximum of three digits is absolutely sufficient. (I mean this solution pgc01 =-LOOKUP (1,-LEFT (A1, {1,2,3,4})) without ";4".)
Unfortunately, that formula (modified to remove the ",4") is not foolproof (this is where the "volunteers watch each other's backs" comment I mentioned earlier comes in... to handle the "blind spots" that crop up). Try the formula with an entry like this...

1E5ABC
 
Upvote 0
Unfortunately, that formula (modified to remove the ",4") is not foolproof (this is where the "volunteers watch each other's backs" comment I mentioned earlier comes in... to handle the "blind spots" that crop up). Try the formula with an entry like this...

1E5ABC

But your example is not correct .... we have max 3 digits and few letters behind :))
So we don't have 1E5ABC but maybe we have 11EABC or 1EABCD :)))

Regards
 
Upvote 0
Unfortunately, that formula (modified to remove the ",4") is not foolproof (this is where the "volunteers watch each other's backs" comment I mentioned earlier comes in... to handle the "blind spots" that crop up). Try the formula with an entry like this...

1E5ABC

But your example is not correct .... we have max 3 digits and few letters behind :))
So we don't have 1E5ABC but maybe we have 11EABC or 1EABCD :)))

Not sure I understand. Why isn't this a possible string based on the OP's original statement? Or if we replace "JX" in the 1st string below with "E7", for example? Where does it say that the "X"s can't be numbers?

I need to extract the numbers at the beginning of a string. The problem is that there could 1, 2 or 3 digits. Here are examples of the string:

4JXXXXXXXXX1204
10EXXXXXXXXX1204
127JXXXXXXXXX1204
 
Upvote 0
For me it was clear.... 4JXXXXXXXXX1204 not 4JXXXX12XXX1204.... digits only at the begining and end of the string.
Maybe I was wrong but I think that gonesalsa put those strings in this way, we can see the numbers are only at the beginning and end.
Regards
 
Upvote 0
It's slightly unfortunate that the "bulk-testing" approach with LEFT (or RIGHT) still probably makes up the majority of proposed solutions to questions of this type, despite its evident lack of rigour.
Okay then, this array-entered formula for getting the leading number from a cell should be fully rigorous...

=LEFT(A1,MATCH(TRUE,ISERROR(1*MID(A1,ROW(INDEX(A:A,1):INDEX(A:A,10)),1)),0)-1)

And while we are at it, this array-entered formula for getting the ending number from a cell should also be fully rigorous...

=RIGHT(A3,MATCH(TRUE,ISERROR(1*RIGHT(A3,ROW(INDEX(A:A,1):INDEX(A:A,10)))),0)-1)
 
Upvote 0

Forum statistics

Threads
1,215,429
Messages
6,124,839
Members
449,193
Latest member
MikeVol

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top