Adding Page Numbers To Footer

Twisted_Squeegie

New Member
Joined
Jan 4, 2018
Messages
6
I have a workbook that is a standard form that I use. I'm trying to get the right footer to print "Page X of Y" but here's the thing, the basic blank workbook has three sheets. The first is a boilerplate sheet, "BLANK", that is always hidden. The second is the actual sheet that the information is typed into. The third is a reference page that isn't printed. The second page is simply titled "Page 1". When I hit New Sheet my code copies "BLANK" and places it before the last sheet and names it Page 2, Page 3, etc.
Generally I only print one sheet at a time, either for a new sheet or correction on an existing. I have this code that works when printing a single page but if I have multiple pages selected it only works on one.
Print page 2 and "Page 2 of X" shows.
Print page 2 and 3, "Page 2 of X" shows but page 3 footer is blank.

Ideas?

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)

x = Worksheets.Count - 2
ActiveSheet.PageSetup.RightFooter = ActiveSheet.Name & " of " & x
ActiveSheet.PageSetup.LeftFooter = "&8Form 108 - Rev. B"
   
End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Try this:

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim sh As Worksheet
Dim x As Integer

x = Worksheets.Count - 2

For Each sh In ThisWorkbook.Windows(1).SelectedSheets

sh.PageSetup.RightFooter = sh.Name & " of " & x
sh.PageSetup.LeftFooter = "&8Form 108 - Rev. B"
   
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,627
Members
452,661
Latest member
Nonhle

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