VBA & Macro Problems

Use an Excel VBA Macro to Number and Print Three-Page Sets

Kushani NimanthikaKushani Nimanthika Nov 18, 2026 870 views

Question details

The user needs to print repeated three-page sets from Excel, with one sequential number shared by all pages in each set.

Use an Excel VBA Macro to Number and Print Three-Page Sets
Product
Microsoft Excel
Device & OS
not provided
Scenario
A worksheet needs to be printed multiple times as three-page sets numbered 001, 002, 003, and so on.
Observed behavior
Each print operation should produce three pages displaying the same three-digit set number, with the number increasing for the next set.
Before you start

Choose a cell for the set number and make sure its row and column can appear on every printed page. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros only if you trust the file.

Solution 1Recommended

Print each numbered set with an Excel VBA loop

Use this method when each print operation should produce the same three worksheet pages with a new set number.

The macro writes a number to J3 and prints the worksheet once per set. Formatting the cell as 000 displays numbers such as 001 without changing their numeric values.

1
Set the print area

Select the worksheet range to print, including column J, then choose Page Layout > Print Area > Set Print Area.

2
Repeat the number row

Choose Page Layout > Print Titles and set Rows to repeat at top to $3:$3. Make sure J3 is visible and that column J appears on every printed page; adjust the layout if the worksheet spans multiple pages horizontally.

3
Check the page count

Open File > Print and inspect all pages in Print Preview. Adjust scaling, margins, or page breaks until one print operation produces exactly three pages, each showing J3.

4
Add the macro

Press Alt+F11, choose Insert > Module, and paste this code. Replace Sheet1 with your worksheet name and change the first and last numbers as needed: Sub PrintSets() Dim ws As Worksheet Dim n As Long Dim firstNumber As Long, lastNumber As Long Set ws = ThisWorkbook.Worksheets("Sheet1") firstNumber = 1 lastNumber = 10 ws.Range("J3").NumberFormat = "000" For n = firstNumber To lastNumber ws.Range("J3").Value = n ws.PrintOut Next n End Sub

5
Run the macro

Return to Excel, select the intended printer in File > Print, then press Alt+F8, select PrintSets, and click Run. The example prints 10 sets, numbered 001 through 010.

Print each numbered set with an Excel VBA loop
Test one set first: Set lastNumber to 1 for a test run. Confirm that all three printed pages show 001 before printing the full sequence.
Free Microsoft Office alternative

Prepare and Print Spreadsheet Pages with WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for opening and editing spreadsheets. Its format compatibility helps you move existing workbooks into WPS, although it does not fix Excel-specific VBA issues and macro support may vary by version.

Use print preview and page layout controls to prepare multi-page spreadsheet sets.Open and edit Microsoft Excel formats such as XLSX for easier migration.Work in a familiar spreadsheet interface.Use a free, lightweight office suite for everyday document tasks.
microsoft office alternative - wps office

Frequently Asked Questions

How do I change the starting and ending set numbers?

In the VBA module, change the firstNumber and lastNumber assignments. For example, use 11 and 20 to print sets numbered 011 through 020.

Why does the number appear on only the first page?

Go to Page Layout > Print Titles and set the row containing the number as a repeating top row. Also check File > Print to confirm that the number cell's column appears on every page.

How can I make Excel display 001 instead of 1?

The macro sets J3's number format to 000. You can also select the cell, open Format Cells > Number > Custom, and enter 000.

What if the worksheet prints more or fewer than three pages?

Open File > Print and adjust scaling, margins, the print area, or page breaks. Check the preview again before running the macro.

Can I use a different cell for the set number?

Yes. Replace both references to J3 in the macro with your chosen cell, then configure Page Layout > Print Titles and the print area so that cell appears on every page.