I have the following text in cell A1 and am trying to replace the -- (double dash) that appears before the 5 digits with a backslash.
My text in A1 looks like this: MD03_Cncr_Elev3_iv---172--00001.mp3
After replacing the -- it should look like this
MD03_Cncr_Elev3_iv---172\00001.mp3
The pattern will always be -- followed by five digits and a period.
This is the code I am using but the replace part is not correct as it replaces the entire pattern with a backslash.
Sub ReplaceDoubleDash()
Dim regex As Object
Dim myCell As Range
Set regex = CreateObject("VBScript.RegExp")
On Error Resume Next
regex.Global = True
regex.Pattern = "[-][-][0-9]{1,5}[.]"
For Each myCell In Selection.Cells
myCell.Value = regex.Replace(myCell.Value, "\")
Next
End Sub
Any help would be appreciated.
Bookmarks