QUESTION: Need numeric value from the alpha numeric text
& same for asddf123yuuui3225
ANSWER: Hi Appavoo,
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
If IsNumeric(Mid(StrIn, iChar, 1)) Then
'look for end of contiguous numeric string characters
nChar = iChar
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
iChar = iChar + 1
Loop Until iChar > Len(StrIn)
ParseNumbers = OutArray
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:
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.
---------- FOLLOW-UP ----------
QUESTION: Need a excel formula not this vba function.
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.