You are here:

# Excel/excel

Question
QUESTION: Need numeric value from the alpha numeric text
qwert1234poo
& same for asddf123yuuui3225

Here is a user-defined function you can use to return the numeric part or parts of a string:
____________________________________________________________

Function ParseNumbers(StrIn As String) As Variant

'returns any numbers found in input string StrIn
'If multiple numeric values are found it returns a zero-based
'array of numerical values.
Dim OutArray()    As Variant
Dim nVals         As Integer     'number of numerical values found
Dim iChar         As Integer
Dim nChar         As Integer

nVals = 0
iChar = 1

Do
If IsNumeric(Mid(StrIn, iChar, 1)) Then
'look for end of contiguous numeric string characters
nChar = iChar
Do
nChar = nChar + 1
Loop Until Not IsNumeric(Mid(StrIn, nChar, 1))
'put found string in array
nVals = nVals + 1
ReDim Preserve OutArray(nVals - 1)
OutArray(nVals - 1) = Mid(StrIn, iChar, nChar - iChar)
iChar = nChar
End If
iChar = iChar + 1
Loop Until iChar > Len(StrIn)

ParseNumbers = OutArray

End Function
____________________________________________________________________

Just place this code in a standard macro module in the Visual Basic Editor.

To use this function for strings with just one numeric part:

=ParseNumbers(A1)

where A1 is the cell containing the string.

If your string has multiple numeric parts, enter the formula in multiple cells in a row as an array function: Select the multiple row cells where you want the result, enter the function (again like =ParseNumbers(A1)) but this time enter the function using Ctrl-Shift-Enter.

Damon

---------- FOLLOW-UP ----------

QUESTION: Need a excel formula not this vba function.
thnks

Hi Appavoo,

I have given quite a bit of thought to methods of accomplishing the extraction of multiple numbers from a text string using only built-in worksheet functions.  I have not come up with a solution for even two embedded numbers.  I believe it is possible, but the formulas would be exceedingly long and complicated (likely array formulas) if the number of numeric fields in the string is greater than two, and I believe it may well be impossible to write a general solution to handle any number of embedded numbers as my UDF does using only worksheet functions.

Just out of curiosity, why must your solution not involve UDFs? Using and understanding a UDF is much easier than using and understanding a long and complicated array function. Do you have a concern about enabling macros? If so, there is a way around this, which is to convert my function to an Add-In.  If you would like to know how to do this let me know and I'll give you the steps.

Damon
This topic answers questions related to Microsoft Excel spreadsheet (or workbook) stand-alone or Mircrosoft Office Excel including Excel 2003, Excel 2007, Office 2000, and Office XP. You can get Excel help on Excel formulas(or functions), Excell macros, charting in Excel, advanced features, and the general use of Excel. This does not provide a general Excel tutorial nor the basics of using a spreadsheet. It provides specific answers to using Microsoft Excel only. If you do not see your Excel question answered in this area then please ask an Excel question here

#### Damon Ostrander

##### Expertise

I have extensive experience with VBA programming in Excel 5 through Excel 2013. As a former aerospace engineer with a large aerospace corporation and consultant in a small defense technology services company, I have developed a wide range of applications in VBA, including simulations involving mixed-language programming, satellite orbit mechanics, graphics and animation, and real-time applications. I am interested in moderate to hard VBA-related questions only.

##### Experience

I have developed and taught several courses in Excel VBA programming and also VBA programming in Office 97, 2000, and 2007. I have developed a number of large technical applications in Excel VBA for use within the aerospace industry.

Education/Credentials
B.S. in Electrical Engineering and Computer Science, University of California, Berkeley.