Custom Page Numbers on Printouts

Written by Allen Wyatt (last updated March 16, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


1

Wendy wants to include page numbers in the header of her worksheet printout, but with a twist—Page 21A on page 1, Page 21B on page 2, Page 21C on page 3, etc. She wonders how to go about creating such a page numbering scheme.

There are a few ways you can go about tackling this problem, all of them involving the use of macros. If you actually want to print all the worksheets in the current workbook and none of those worksheets is over a single page in length (when printed), then the following macro will set the center section of the header as requested:

Sub PageNums1()
    Dim sheet As Worksheet
    Dim J As Integer

    J = 1
    On Error Resume Next
    For Each sheet In Worksheets
        Sheets(J).PageSetup.CenterHeader = "Page 21" & Chr(64 + J)
        J = J + 1
    Next
End Sub

Note that the macro doesn't actually print anything; all it does is to change the header information. If you really only want to print out the current worksheet and that worksheet will require multiple pages on the printout, then the following should work just fine:

Sub PageNums2()
    Dim X As Integer
    Dim Y As Integer
    Dim Z As Integer

    Z = 1
    For X = 1 To ActiveSheet.HPageBreaks.Count + 1
        For Y = 1 To ActiveSheet.VPageBreaks.Count + 1
            ActiveSheet.PageSetup.CenterHeader = _
              "Page 21" & Chr(64 + Z)
            Worksheets.PrintOut Z, Z
            Z = Z + 1
        Next Y
    Next X
End Sub

This macro calculates pages based on the position of the horizontal (HPageBreaks) and vertical (VPageBreaks) page breaks on the printout. You could also try just working with the Pages collection, in this manner:

Sub PageNums3()
    Dim J As Integer

    For J = 1 To ActiveSheet.PageSetup.Pages.Count
        ActiveSheet.PageSetup.CenterHeader = "Page 21" & Chr(64 + J)
        Worksheets.PrintOut J, J
    Next J
End Sub

You should note that regardless of the approach you select, you'll run into problems if the printout requires more than 26 pages.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12548) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Changing the Color Inside a Shape

Adding a shape to your workbook is easy. If you want to fill the shape with a color, you'll want to follow the ...

Discover More

Combining First and Second Numbered Levels on One Paragraph

Want to customize your paragraph numbering in Word? There are a few tricks that can be used to automatically display the ...

Discover More

Changing Body Text to a Heading

When working on a document in Outline view, you may need to change regular body text to a heading in the outline. It's ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Printing Only Non-Blank Worksheets

If you have a workbook containing many worksheets, you might want to print only those worksheets that have some sort of ...

Discover More

Repeating Rows on a Printout Except On the Last Page

When setting up a worksheet for printing, you can specify that Excel repeat some of your rows at the top of each page ...

Discover More

Specifying Print Quantity in a Cell

When you print a worksheet, you can specify in the Print dialog box how many copies you want printed. If you want the ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 7?

2024-03-16 10:35:33

J. Woolley

To avoid "problems if the printout requires more than 26 pages," substitute the following instead of Chr(64 + J):
    Split(Columns(J).Address(False, False), ":")(0)
This converts relative column addresses like A:A, B:B, ..., AA:AA, AB:AB, ... into A, B, ..., AA, AB, ....


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.