Hi -
You might try copying/pasting this to a standard module:
Function SaveNumer2(ByVal pStr As String) As Long
'*******************************************
'Purpose: Removes alpha characters from
' a string
'Coded by: raskew
'Calls: Function IsNumeric()
'Inputs: ? SaveNumer2("ABC234BB")
'Output: 234
'*******************************************
Dim strHold As String
Dim intLen As Integer
Dim n As Integer
strHold = Trim(pStr)
intLen = Len(strHold)
n = 1
Do
If Mid(strHold, n, 1) <> " " And Not IsNumeric(Mid(strHold, n, 1))
Then
strHold = Left(strHold, n - 1) + Mid(strHold, n + 1)
n = n - 1
End If
n = n + 1
Loop Until val(strHold) > 0
SaveNumer2 = val(strHold)
End Function
*********************************************
...then call it like this:
? SaveNumer2("AS0090040101")
90040101
Note that 'real' numbers do not have preceding zeros, so
this function returns the numeric value as a long.
If you wanted to return just the first four real digits,
regardless of their placement in your input:
:
? val(Left(SaveNumer2("AS0090040101"),4))
9004
Note that this returns a long integer. Remove the Val()
and it'll return the same as a string.
HTH - Bob