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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
20,375
Office Version
  1. 365
Platform
  1. Windows
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,887
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
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
20,375
Office Version
  1. 365
Platform
  1. Windows
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,171,254
Messages
5,874,684
Members
433,066
Latest member
Adsmit83

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