Solved

extract numeric from text string

Posted on 2014-04-28
3
306 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 26

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now