Extracting Letters from the String

  • Guys,
    Need to extract all the letters within the string , separated by comma.
    Now the code extracts first letters only.
    Please your help with modifying an user defined function:


    Input: HKJ234CBV546LL
    Output (is): HKJ
    Output (ought): HKJ,CBV,LL

  • Hello,


    You can test following UDF


    Code
    Function RemoveNumbers(Txt As String) As String
      With CreateObject("VBScript.RegExp")
        .Global = True
        .Pattern = "[0-9]"
        RemoveNumbers = .Replace(Txt, " ")
      End With
    End Function


    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Thumbs Up" icon, below, in the bottom right corner:)

  • Thank you!


    You are welcome ... :wink:


    Should you need to insert commas between the letters ... you could add following instruction :


    Code
    RemoveNumbers = Replace(Application.WorksheetFunction.Trim(RemoveNumbers), " ", ",")


    Hope this will help

    If you feel like saying "Thank You" for the help received, do not hesitate to click the "Thumbs Up" icon, below, in the bottom right corner:)

Participate now!

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