locating and extracting numeric characters in a text string

bmantych

New Member
Joined
Dec 22, 2004
Messages
8
Hi,

I am trying to figure out how to extract numbers that are in various positions within a text string.

For example, I have 'abc123ef' in a cell and I want a formula that will find where the number starts (in this case, position 4 but it won't be in the same place in each example) and ends and the pull just the number (123) out.

The next cell in the column may contain '12abcdefgh' and I'd need only to extract the '12'.
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,696
Assuming that there are no other numbers within the text string, other than the ones appearing consecutively, try...

=MID(A2,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A2&"0123456789")),SUMPRODUCT(LEN(A2)-LEN(SUBSTITUTE(A2,{0,1,2,3,4,5,6,7,8,9},""))))

Hope this helps!
 

pgc01

MrExcel MVP
Joined
Apr 25, 2006
Messages
19,884
Beautiful formula, Domenic!
I was trying, but could't get the third parameter of the MID.

Cheers
PGC
 

Krishnakumar

Well-known Member
Joined
Feb 28, 2003
Messages
2,615

ADVERTISEMENT

Another approach..

=LOOKUP(9.9999999999E+307,--MID(REPLACE(A2,1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A2&"0123456789"))-1,""),1,ROW(INDEX(A:A,1):INDEX(A:A,LEN(A2)))))

HTH
 

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,696
Another approach..

=LOOKUP(9.9999999999E+307,--MID(REPLACE(A2,1,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A2&"0123456789"))-1,""),1,ROW(INDEX(A:A,1):INDEX(A:A,LEN(A2)))))

HTH

Note, however, that the formula will omit any leading zeros...
 

Forum statistics

Threads
1,136,268
Messages
5,674,734
Members
419,523
Latest member
Urnovio

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
Top