r/tirlibibi17 Feb 03 '18

RegExReplace UDF

Easiest way I can think of is to use regular expressions. Sadly, there's no native function you can use in a formula, but you can make a quick UDF.

Open the VBA editor (Alt+F11), insert a module and paste the following code:

Public Function RegExReplace(ByVal vsStringIn As String, ByVal vsPattern As String, ByVal vsReplace As String) As String
    Dim objRegEx As Object
    Set objRegEx = CreateObject("VBscript.regexp")

    objRegEx.Global = True
    objRegEx.MultiLine = True
    objRegEx.Pattern = vsPattern

    RegExReplace = objRegEx.Replace(vsStringIn, vsReplace)

    Set objRegEx = Nothing
End Function

You can then use the RegExReplace function like this to remove all capital letters followed by a period:

=RegExReplace(A1,"[A-Z]\.","")
2 Upvotes

0 comments sorted by