Page Setup: Title Rows, Header and Footer with References

mharper90

Board Regular
Joined
May 28, 2013
Messages
117
Office Version
  1. 365
Platform
  1. MacOS
I'm trying to use .PageSetup to get a few pages in a workbook ready for print, but I'm having trouble getting the expected response with Title Rows, and I can't find a good code example for using VBA to insert a header (and footer) with cell references.

Below is the code that I have, and I need to add to it 1) Title Rows 1 and 2 to print at the top of every page, 2) a center page header that says "(the contents of Sheets("Main Data").Range(C4)) TLD Period (the contents of Sheets("Main Data").Range(C2))", and 3) a center page footer that says "(the current page number) of (total pages)".

I'm aware that I can set the first and third items easily in the page setup window (I don't know how to use cell references for the header), but I'm trying to make this file idiot proof for future users, so I would like VBA to have hidden control in case a user messes up the page setup properties available within the main file.

Code:
Lr = Sheets("Figure 2-2").Range("B" & Rows.Count).End(xlUp).Row

With Sheets("Figure 2-2")[INDENT].PageSetup.PrintArea = "A:F" & Lr
.PageSetup.Orientation = xlPortrait
.PageSetup.FitToPagesWide = 1
.PageSetup.FitToPagesTall = False
.PrintPreview[/INDENT]
End With
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top