I have a sheet that I use an Excel VBA macro to automatically fill all worksheet page headers (NOT column headers) with relevant information on a button click. This macro uses wSheet.Name to populate the header title. However, wSheet.Name often contains leading numbers, periods, and spaces that I don't want to appear in the header.
Note the following sample worksheet names:
Cover Page
1a. Test Page
1b. Sample Page
2. Another Test Page
3. Yet Another Test Page
4. Almost the Last Example Page
998. Last Example Page
I would like to remove these leading numbers, periods, and spaces using a regular expression, yet I'm unsure how to code it using VBA in Excel. I would like it to be as flexible as possible. Here is an example of how I would like the worksheet names to appear:
Cover Page
Test Page
Sample Page
Another Test Page
Yet Another Test Page
Almost the Last Example Page
Last Example Page
Here is my existing code that populates the headers:
Sub FillHeaders()
'
' Auto_Fill_Project_Name Macro
'
For Each wSheet In ActiveWorkbook.Worksheets
If wSheet.Name <> "Cover Page" Then
wSheet.PageSetup.CenterHeader = _
"&16&KFF0000" & ActiveSheet.Range("J1") & "&10&K000000 &16" & " " & _
wSheet.Name & Chr(13) & "&10 &11 Revision Date: "
End If
Next wSheet
'
End Sub
How can I modify this to accomplish my goal?
Thank you!
EDIT -- I have taken the following approach:
Function remleaddig(str As String)
Set regEx = CreateObject("VBScript.RegExp")
regEx.Pattern = "^\S*\."
str = regEx.Replace(str, "")
remleaddig = Trim(str)
End Function