I am trying to add a 0 before two digits in a title across hundreds of rows. I am trying to use VBA regex. There is something I am not understanding about regex. This is what a title looks like:
The BigBook, Vol. 1, No. 1 <== The end result should look like ==> The BigBook, Vol. 01, No. 01 (there are 1 - 9 Vol. nums and No. nums)
Here is my test code so far.
Sub RegexReplace1()
Dim stringOne As String
Dim regexOne As Object
Set regexOne = New RegExp
regexOne.Pattern = "Vol. [0-9], No. [0-9]"
regexOne.Global = True
stringOne = "The BigBook, Vol. 1, No. 1"
Debug.Print regexOne.replace(stringOne, "Vol. 0[0-9], No. 0[0-9]")
End Sub
I think I'm close...but can't seem to figure this out. Any help would be appreciated. Thanks.
Hi Armando,
I'd just use SUBSTITUTE
str = WorksheetFunction.Substitute(Range("A1"), ". ", ". 0")
where your title is in A1.
Regards
Phil