Sub topic 3
Adding Headers, Footers, and Page Numbers
Assume you can navigate Excel’s ribbon and already understand worksheets, workbooks, and cell ranges. This chapter focuses on controlling output after the print area and page breaks are set.
Headers, footers, and page numbers
In Page Layout view, select Insert > Header & Footer. Click a header or footer section, then use the Header & Footer tab. Common fields include:
&F File name
&A Sheet name
&D Current date
&P Page number
&N Total number of pagesFor example, enter Page &P of &N in the center footer. Headers and footers appear on printed pages and in PDFs, but not in the normal worksheet grid.
Sheet options
Use Page Layout > Sheet Options to decide whether Excel prints gridlines and row or column headings. These options are independent of the screen display. In Page Setup, you can also control comments and notes, and choose whether cell errors print as displayed, blank, or a marker such as --.
| Option | Typical use |
|---|---|
| Gridlines | Useful for raw data tables, but often omitted from polished reports |
| Headings | Prints row numbers and column letters for reference |
Exporting to PDF
Use File > Export > Create PDF/XPS or Save As > PDF. Excel can export the active sheet, a selected range, or the entire workbook, depending on the selected publishing option. Check Print Preview first. PDF export follows the print area, scaling, breaks, titles, and page setup.
Fixing common output problems
- Cut-off columns: use landscape orientation, wider paper, smaller margins, or Fit All Columns on One Page.
- Blank pages: clear an accidental print area and remove stray formatting far below or to the right of the data.
- Tiny text: avoid fitting too many pages tall and wide. Prefer a readable multi-page report over extreme scaling.
- Missing repeated headings: set Print Titles for the rows or columns that identify each page.
Automating setup with VBA
This macro applies consistent settings and exports the active sheet beside the workbook.
Sub SetupAndExportReport()
With ActiveSheet.PageSetup
.PrintArea = "$A$1:$H$60"
.Orientation = xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
.PrintTitleRows = "$1:$1"
.CenterFooter = "Page &P of &N"
End With
ActiveSheet.ExportAsFixedFormat _
Type:=xlTypePDF, _
Filename:=ThisWorkbook.Path & "\Report.pdf", _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
End SubExercise
Why might a PDF contain tiny text even though every column is visible?
Show answer
The worksheet is being scaled to fit too many columns or pages onto the selected page dimensions. Reduce the fit requirement or use landscape orientation.