Extract numbers from text (2 Viewers)

pbaldy

Wino Moderator
Staff member
Local time
Today, 08:41
Joined
Aug 30, 2003
Messages
36,118
Gasman gave you a workaround in post 19. Another alternative is a function that loops through every character and only returns numeric ones.
 

GT 11

New member
Local time
Today, 21:11
Joined
May 13, 2019
Messages
4
Thanks a lot. It works with your suggestion" strHold = Replace(Trim(pStr), ".", ":") ". This helps to shed off the alpha or special characters so that an invoice number could be read as a general index number to prevent duplicate payments.
 

Reshmi mohankumar

Registered User.
Local time
Today, 21:11
Joined
Dec 5, 2017
Messages
101
Hi -

Try copying the following to a module, then call as shown:

Code:
Function SaveNumer2(ByVal pStr As String) As Long
'*******************************************
'Purpose:   Removes alpha and non-numeric 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

HTH - Bob
it helped me today. thank you
 

Users who are viewing this thread

Top Bottom