i'am new to VBA and i am trying to lookup a function that deletes for each Cell in a Column the next two Strings after an Regular Expression.
Below the RegEx
[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1]) (2[0-3]|[01][0-9]):[0-5][0-9]
Here is some of the code I wrote
Private Sub DeleteRegexPattern()
Dim xRg As Range
Dim regEx As New RegExp
Dim strPattern As String
Dim strInput As String
Dim Myrange As Range
Set Myrange = Application.InputBox("Select a range:", "PivData Hider", xTxt, , , , , 8)
Set Myrange = Application.Intersect(Myrange, Myrange.Worksheet.UsedRange)
If Myrange Is Nothing Then Exit Sub
For Each C In Myrange
KIDPattern = ("([A-Z]{1})([0-9]{5})| |(.*)@.*")
emailPattern = "(.*)@.*"
If KIDPattern <> "" Then
strInput = C.Value
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = KIDPattern
End With
If regEx.Test(strInput) Then
C.Value = regEx.Replace(strInput, "")
End If
End If
Next
End Sub
Example Input
2017-02-14 19:30 John Smith
Output
2017-02-14 19:30
John Smith is removed or replaced with ""
I want to delete John Smith
but dont know how to. Any Ideas?