• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 319
  • Last Modified:

extract numeric from text string

I have text strings and I would like to be able to extract only the number contained within.

ie
GSX-R 1100 M (GSX-R M), GSX-R 1100 N (GSX-R N) = 1100
GSX 750/K1/W/X/Y= 750

GZ 125 K=125

am with microsoft 365 version and working in query grid.

help would be appreciated.
0
PeterBaileyUk
Asked:
PeterBaileyUk
1 Solution
 
MacroShadowCommented:
This function will return the numeric part of a string:
Function fExtractText(ByVal strInput As String) As String
    With CreateObject("VBScript.RegExp")
        .Pattern = "\D+"
        .Global = True
        fExtractText = .Replace(strInput, "")
    End With
End Function

Open in new window


Sample usage:
Sub Demo
    MsgBox(fExtractText("GSX-R 1100 M (GSX-R M)"))
End Sub

Open in new window

0
 
GanapathiCommented:
Function ExtractNumbers(ByVal str As String) As String
    num = ""
    For x As Integer = 0 To str.Length - 1
        If IsNumeric(str.Substring(x, 1)) Then num = num & str.Substring(x, 1)
    Next
    return num
End Function

Open in new window

0
 
PeterBaileyUkAuthor Commented:
thx
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now