Consulting

Results 1 to 3 of 3

Thread: Solved: Remove commas and spaces in the middle of a string

  1. #1
    VBAX Regular
    Joined
    May 2008
    Posts
    26
    Location

    Question Solved: Remove commas and spaces in the middle of a string

    I have a bunch of strings with commas and spaces in the middle of them and i need to remove the commas and spaces and replace them with a "-". The comma will not always be in the same place and sometimes there may be spaces on both sides of the comma but my goal is to make the string go from eg. "abc, 123" to "abc-123" or "abc , 123" to "abc-123" or "abc ,123" to "abc-123" the string will not always be the same length either. Thanks

  2. #2
    [vba]Function RemoveThings(sParam As String) As String
    Dim Result As String
    Result = sParam
    Do
    Result = Replace(Result, " ", "-")
    Result = Replace(Result, ",", "-")
    Result = Replace(Result, "--", "-")
    Loop Until InStr(Result, "--") = 0
    RemoveThings = Result
    End Function
    [/vba]

    This should work with a string of any length, with commas and spaces of any number, in any position.

    HTH
    Jimmy
    -------------------------------------------------
    The more details you give, the easier it is to understand your question. Don't save the effort, tell us twice rather than not at all. The amount of info you give strongly influences the quality of answer, and also how fast you get it.

  3. #3
    VBAX Regular
    Joined
    May 2008
    Posts
    26
    Location
    Works Perfect Thank You!

Posting Permissions

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