# locating and extracting numeric characters in a text string

#### bmantych

##### New Member
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
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
Beautiful formula, Domenic!
I was trying, but could't get the third parameter of the MID.

Cheers
PGC

#### Krishnakumar

##### Well-known Member
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
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...

#### Krishnakumar

##### Well-known Member
Yes, I didn't notice that

Replies
15
Views
307
Replies
14
Views
1K
Replies
11
Views
249
Replies
2
Views
404
Replies
2
Views
209

1,171,254
Messages
5,874,684
Members
433,066
Latest member

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

### Which adblocker are you using?

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

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