Results 1 to 6 of 6

Thread: Remove Special Characters From Text Or Remove Numbers From Text

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Excel Fox's Avatar
    Join Date
    Mar 2011
    Posts
    1,402
    Rep Power
    10

    Remove Special Characters From Text Or Remove Numbers From Text

    Code:
     
    Enum WhatToRemove
        Text
        Numeric
        SpecialCharacters
    End Enum
    Function RemoveCharacters(ByVal StringToReplace As String, WhatRemove As WhatToRemove) As String 
        Dim RegEx As Object
        
        Set RegEx = CreateObject("VBScript.RegExp")
        
        With RegEx
            .Global = True
            Select Case WhatRemove
                Case Text
                    .Pattern = "[A-Za-z]"
                Case Numeric
                    .Pattern = "\d"
                Case SpecialCharacters
                    .Pattern = "[\;+\.+\#+\!+\'+\*+\,+\+\^+\&+\*+\@+\(+\)]"
            End Select
        End With
        
        RemoveCharacters= RegEx.Replace(StringToReplace, "")
        
        Set RegEx = Nothing
        
    
    End Function
    Last edited by Excel Fox; 05-31-2013 at 12:27 PM. Reason: Revised After Rick's Comment

Similar Threads

  1. Extract Certain Characters From A Text String
    By bobkap in forum Excel Help
    Replies: 5
    Last Post: 05-24-2013, 06:25 AM
  2. Replies: 10
    Last Post: 12-10-2012, 11:28 PM
  3. Remove Numerics From Text
    By VIMAL CHALISSERY in forum Excel Help
    Replies: 2
    Last Post: 04-12-2012, 08:43 PM
  4. Remove Special Characters :
    By Rajan_Verma in forum Rajan Verma's Corner
    Replies: 3
    Last Post: 03-06-2012, 09:41 PM
  5. Remove Zero / Zeroes From Alphanumeric Text
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 04-04-2011, 01:16 AM

Posting Permissions

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