Consulting

Results 1 to 3 of 3

Thread: Extracting Letters from the String

  1. #1

    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:
    Function ExtractLetter(str As String)
        Dim TDCode As String
        Dim result As String
        
        On Error GoTo ErrHandler:
        With CreateObject("vbscript.regexp")
            .Pattern = "[A-Z]+"
            ExtractLetter = .Execute(str)(2)
        End With
        Exit Function
    ErrHandler:
    End Function

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

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Cross-posted (and answered) here: https://www.excelforum.com/excel-pro...he-string.html
    Be as you wish to seem

  3. #3
    Solved!

    Function ExtractLetter(myStr As String)
    ' function that extract letters from string using Regular Expressions
        With CreateObject("vbscript.regexp")
            .Global = True
            .Pattern = "[^A-Z]+"
            ExtractLetter = Replace(Application.Trim(.Replace(myStr, " ")), " ", ",")
        End With
    End Function

Posting Permissions

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