Insert page numbers into header
This tutorial shows how to insert page numbers into a header in a specific sheet using Excel and VBA
Insert tab > Text group > Header & Footer > Select header area > Design tab > Header & Footer Elements group > Page Number > Click anywhere on the sheet
1. Select the Insert tab. |
2. Select the Text group. 3. Click on Header & Footer. |
4. Select header area in which you want to show the page number. Note: In this example we have selected the center header area. |
5. Select the Design tab. 6. Click on Page Number in the Header & Footer Elements group. |
7. This will insert &[Page] in the selected header area which will show the page number when you are working in the sheet. 8. Click anywhere on the sheet. |
Sub Insert_Page_Numbers_Header()
'declare a variable
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
With ws.PageSetup
.CenterHeader = "&P"
End With
End Sub
NOTES
Note 1: This VBA code will insert page numbers into the center header area of "Sheet1".
Note 1: This VBA code will insert page numbers into the center header area of "Sheet1".
RELATED TOPICS
Related Topic | Description | Related Topic and Description |
---|---|---|
Insert a header | How to insert a header | |
Insert a footer | How to insert a footer in a specific sheet | |
Insert page numbers into footer | How to insert page numbers into a footer in a specific sheet |