Solved

extract numeric from text string

Posted on 2014-04-28
3
310 Views
Last Modified: 2014-04-28
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
Comment
Question by:PeterBaileyUk
3 Comments
 
LVL 27

Accepted Solution

by:
MacroShadow earned 500 total points
ID: 40026780
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
 
LVL 8

Expert Comment

by:Ganapathi
ID: 40026841
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
 

Author Closing Comment

by:PeterBaileyUk
ID: 40026880
thx
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

837 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question