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

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
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!
 
Upvote 0
Beautiful formula, Domenic!
I was trying, but could't get the third parameter of the MID.

Cheers
PGC
 
Upvote 0
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
 
Upvote 0
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...
 
Upvote 0

Forum statistics

Threads
1,222,151
Messages
6,164,246
Members
451,882
Latest member
Bigtop

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