Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8788097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:05:06+00:00 2026-06-13T22:05:06+00:00

I have a sheet that I use an Excel VBA macro to automatically fill

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:05:07+00:00Added an answer on June 13, 2026 at 10:05 pm

    Update: — Added UDF

    Function StripChars(strIn As String) As String
    Dim objRegex As Object
    Set objRegex = CreateObject("vbscript.regexp")
     With objRegex
     .Pattern = "^.+\.\s+"
    .ignorecase = True
    StripChars = .Replace(strIn, vbNullString)
    End With
    End Function
    

    Initial Post`

    I would combine the regexp with a variant array to reduce code runtime. The code below uses

    1. Late bindging to set up the regexp
    2. The values in column A of the ActiveSheet are read into a variable array X (Note that the code will handle a 2D range, ie you could use X = Range([a1], Cells(Rows.Count, "B").End(xlUp)).Value2 to work on column A and B
    3. The regexp strips out the unwanted characters – it will handle more than one space if it is presnt before the text you want to retain
    4. The cleaned text is dumped to the active sheet starting in C1. Change this line to move the dump – you could make it dump back over the orginal values starting in A1. [c1].Resize(UBound(X, 1), UBound(X, 2)).Value2 = X

    enter image description here

    Code

    Sub QuickUpdate()
    Dim X()
    Dim objRegex As Object
    Dim lngRow As Long
    Dim lngCol As Long
    
    X = Range([a1], Cells(Rows.Count, "A").End(xlUp)).Value2
    Set objRegex = CreateObject("vbscript.regexp")
     With objRegex
     .Pattern = "^.+\.\s+"
    .ignorecase = True
    For lngRow = 1 To UBound(X, 1)
    For lngCol = 1 To UBound(X, 2)
    X(lngRow, lngCol) = .Replace(X(lngRow, lngCol), vbNullString)
    Next lngCol
    Next lngRow
    End With
    
    [c1].Resize(UBound(X, 1), UBound(X, 2)).Value2 = X
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an excel sheet that has several headers. One of the header is
I have an excel sheet that I want to load into a datatable withe
I have an excel sheet that is organized as follows: COL1 COL2 1 30
I have the this code that will create excel file and work sheet then
I am have the following code for excel vba that will email a range
I have a sheet in Excel. One column in it (ID) contains strings with
I have an excel vba problem that I am trying to solve and after
I have an excel sheet that has dde links to real time market data.
I'm trying to call an Excel macro that's in another workbook. It's a sheet-specific
I'm trying to use the DateDiff function for a macro in excel using VBA.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.