
Tips.Net > ExcelTips Home > Page Setup > Headers and Footers > Selective Headers and Footers
Summary: Excel’s tools for creating headers and footers aren’t that great, which means you might not be able to control the headers and footers like you may need to. This tip explains how you can use a macro to selectively print headers or footers on only some of the pages of your worksheet. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, and Excel 2003.)
One of the long-time complaints about Excel is that it doesn't have a very robust method of creating and managing headers and footers. Consider the following scenario: You want to print your worksheet, but only have page numbers beginning on the second page.
There is no intrinsic method in Excel to handle this situation. There are some workarounds; for instance, you could put your first page on one worksheet (without headers or footers) and the subsequent pages on a different worksheet (which includes headers and footers). You could then print the two worksheets in one pass, and effectively achieve your goal. You could also use the Report Manager to put together different reports based on the information in your worksheet. (Using the Report Manager has been covered in other issues of ExcelTips.)
Neither of these approaches will work for all situations, however. For instance, you may not be able to split your printout into multiple worksheets, or you may not have much experience with the Report Manager. If you prefer, you can create a macro which will print your worksheet as you desire.
The following macro, GoodPrint, will print the first page of a worksheet without headers or footers, and then all subsequent pages as normal.
Sub GoodPrint()
Dim hlft As String
Dim hctr As String
Dim hrgt As String
Dim flft As String
Dim fctr As String
Dim frgt As String
'save current header
hlft = ActiveSheet.PageSetup.LeftHeader
hctr = ActiveSheet.PageSetup.CenterHeader
hrgt = ActiveSheet.PageSetup.RightHeader
'save current footer
flft = ActiveSheet.PageSetup.LeftFooter
fctr = ActiveSheet.PageSetup.CenterFooter
frgt = ActiveSheet.PageSetup.RightFooter
'remove header
With ActiveSheet.PageSetup
.CenterHeader = ""
.RightHeader = ""
.LeftHeader = ""
.CenterFooter = ""
.RightFooter = ""
.LeftFooter = ""
End With
'print page one
ActiveSheet.PrintOut 1, 1
'restore header
With ActiveSheet.PageSetup
.LeftHeader = hlft
.CenterHeader = hctr
.RightHeader = hrgt
.LeftFooter = flft
.CenterFooter = fctr
.RightFooter = frgt
End With
'print the rest of the pages
ActiveSheet.PrintOut 2
End Sub
Tip #2189 applies to Microsoft Excel versions: 97 2000 2002 2003
Organize Your Data! Using the powerful sorting capabilities of Excel can help you get your data into just the order you need. Find out how you can use the full capabilities of sorting to your benefit.
Check out ExcelTips: Serioius Sorting today!
Thousands of ExcelTips, available for immediate download. Have all the Microsoft Excel info you need, right at your fingertips. (more information...)
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site