+ Reply to Thread
Results 1 to 2 of 2

Only numbers from strin?

  1. #1
    Registered User
    Join Date
    12-22-2004
    Posts
    7

    Only numbers from strin?

    hello

    Can someone pls tell me how to get only numbers from a string?

    exp:

    string = "ABC129" or "A12CD" or any other combinations so i cant simply use left or right funtion...

    and i want to get only "129" or "12" in my output sting2

    thx

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Sasolini,

    You need to strip the numbers from the string and build a new string of only number. This macro code will do that for you.

    Macro Code:
    Public Function NumbersOnly(ByVal String_To_Convert As String) As String

    Dim I As Integer
    Dim NumStr As String
    TestChr As Integer

    For I = 1 To Len(String_To_Convert)
    TestChr = Asc(Mid(String_To_Convert, I, 1))
    If TestChr > 47 And TestChr < 58 Then
    NumStr = NumStr & Chr(TestChr)
    End If
    Next I

    NumbersOnly = NumStr

    End Function


    Using the Macro:
    NumberString = NumberOnly("ABC123XYZ06SLF")

    NumberString will contain the string "12306"

    Hope this helps,
    Leith Ross

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1