Remove numbers from a string

  • Hi,

    Is it possible to remove the numbers from the end of string variable using a simple VB function?

    I tried:

    strString = Replace(strString, ISNUMBER, "")

    But it is clearly wrong, and even if it worked it would remove both 27's in the middle example below.

    i.e I want strings:
    "Number 23", "My 27 Isn't 27", "Test 44 5"

    To be converted to:
    "Number", "My 27 Isn't", "Test"

    My full code is:

    lngLastC = .Range("C65536").End(xlUp).Row
                Dim rn As Integer
                rn = 1
                ReDim strName(intNumRunners)
                    For Each rngRunners In .Range("C3:C" & lngLastC)
                        strName(rn) = rngRunners.Value
                        [B]strName(rn) = Replace(strName, IsNumber, "")[/B]
                        strName(rn) = RTrim(strName(rn))
                        rn = rn + 1
                    Next rngRunners

    (where the bold line is where I need to trim the string)

    If this isn't possible, could somebody please show me how I would loop backwards through a string removing any numbers until I reached a digit that wasn't a space or a number?



  • Re: Remove numbers from a string

    Try using this VBA function instead of the replace code

  • Re: Remove numbers from a string

    If I understand correctly, you only want numbers deleted from the end of the string, not from the middle. I think Will's function deletes all numbers. This version of Will's macro works from the end of the string, works its way backwards, and stops deleting when a non-number is encountered.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!