# Extracting numeric values from text

Folks,
I'm using the following array function to extract numbers from text and the only value I get is from the first item in my list
``````{=1*MID(A2,MATCH(FALSE,ISERROR(1*MID(A2,ROW(\$1:\$8),1)),0),255)}
``````
Here is my list:
asw345
TQ7F
Z798Bc
147JUl9
B42flat
Befr6733
YTK2000

The only number returned is 345 for each item in the list
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Older than dirtCommented:
Put this UDF in a module and then use it as you would any formula. For example =(A2)

``````Function GetNumber(r As Range) As Long
Dim lngIndex As Long
Dim strTemp As String

For lngIndex = 1 To Len(r.Value)
If IsNumeric(Mid(r.Value, lngIndex, 1)) Then
strTemp = strTemp & Mid(r.Value, lngIndex, 1)
End If
Next

GetNumber = CLng(strTemp)
End Function
``````
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
That formula only works when all the numbers are at the end like with asw345, if you want to extract all digits, so 147JUl9 gives 1479 then you need a more complex formula.

Try this version for extracting up to 25 digits

=MID(SUMPRODUCT(--MID("01"&A1,SMALL((ROW(\$A\$1:\$A\$25)-1)*ISNUMBER(-MID("01"&A1,ROW(\$A\$1:\$A\$25),1)),ROW(\$A\$1:\$A\$25))+1,1),10^(25-ROW(\$A\$1:\$A\$25))),2,25)

confirmed with CTRL+SHIFT+ENTER

.....but in this case Martin's suggestion would probably be better for you.....

regards, barry
0
Older than dirtCommented:
I'm sorry my example should have been

=GetNumber(A2)
0
Author Commented:
My question back to the both of you is this:
In my array function why am I only getting the first number in my list and not the rest?
0
Older than dirtCommented:
Sorry but I don't know. My strength is in VBA rather than formulas.
0
Commented:
If you are getting 345 on every row then I think you have entered the formula incorrectly as an array formula over a range. If you try to delete the formula in one cell only does Excel let you?

You have selected the whole range and then pressed CTRL+SHIFT+ENTER

Try deleting the formula from all rows and then enter it again in the first row and apply CTRL+SHIFT+ENTER. When that is working you should then copy the formula down the column

regards, barry
0
Author Commented:
Barry,
I followed your suggestion and I'm OK now - kind of. I've run into a problem though and VBA, as Martin suggested, maybe the only solution. The functions works as long as the numeric values are at the end of the text, not embedded within or before. Any other place and I get the #VALUE error. I'm going to accept both solutions equally.
Thank you Martin and Barry
0
Author Commented:
Thank you gentlemen - hopefully you each got 250 points for that's my goal.
Good work!
0
Older than dirtCommented:
Yes we did. You're welcome and I'm glad I was able to help.

Marty - MVP 2009 to 2013
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.