I found an article on VBAExpress that helped me to implement Regular Expression search on Excel, using VBA:

Sub RegExp_Late_Replace_1()
'Late binding
'Dimension the RegExp objects
Dim RegEx As Object
Dim Myrange As Range, C As Range

' create the RegExp Object with late binding
Set RegEx = CreateObject("vbscript.regexp")

' set the RegExp parameters
With RegEx
'look for global matches
.Global = True
'look for strings that are not numeric
' Dave's original pattern was "[^\d]+"
.Pattern = [Example1PatternB]
End With

' set the Excel range to parse the ActiveSheet B3:B12
Set Myrange = ActiveSheet.Range("B3:B12")

For Each C In Myrange
' Replace non numeric strings with ""
C.Offset(0, 1) = RegEx.Replace(C.Value, "")
Next

Set Myrange = Nothing
Set RegEx = Nothing

End Sub

0 comments:

Newer Post Older Post Home