Limit header page numbers to only certain pages

Milos

Board Regular
Joined
Aug 28, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi all,

Does anyone know if there would be a way to reshape or remove page setup headers that will exclude the last page of an active sheet? I currently have this macro inputting text "Page not used" when the data in each worksheet is oddly numbered. This makes an empty "dummy page" (as I am calling it) which converts all odd numbered worksheets evenly numbered. Printing the entire workbook with this macro is thus easy.

Example: In Sheet 3 I only have 5 pages worth of data but the macro below adds a sixth dummy page. What I am after is a way to stop the header for the dummy page so that it will only number pages 1-5 etc.

Could anybody let me know if this is even possible? My internet searches lead me to believe that it may not be...

Code:
Sub Page_Not_Used ()
'Button 6
Dim lr As Long, ws As Worksheet


Application.ScreenUpdating = False


For Each ws In ThisWorkbook.Worksheets
      With ActiveSheet.PageSetup
            .RightHeader = "&P of &N"
      End With
            
     With ws
        .Activate
        If .PageSetup.Pages.Count Mod 2 = 1 Then
            lr = .Cells.Find(What:="*", SearchDirection:=xlPrevious, SearchOrder:=xlByRows).Row
            .HPageBreaks.Add Before:=Rows(lr + 1)
            .Cells(lr + 1, 1).Value = "Page not used" 
        End If
    End With
Next ws


Application.ScreenUpdating = True


End Sub

Cheers,
Milos
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Would this work for you ?
(may cause problem if printing double-sided etc???)

SheetX
- insert NEW "SheetX" into your workbook
- SheetX comprises one cell with value "Page not used"
- SheetX has no headers and no footers

Printing
- do not add a dummy page break
- amend your printing code to print SheetX when Printed Sheet's PageSetup.Pages.Count Mod 2 = 1
 
Upvote 0
Thanks Yongle that was a great idea I do not know why I never thought of that! I tried what you said and it has worked (partly). For some reason my entire workbook now seems to be printing with sequential page numbers rather than non-sequential (e.g. 1, 2, 3, 4, 5, 6 vs. 1,2,3 & 1,2,3). I will make a new thread to sort that out...
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,517
Members
449,088
Latest member
RandomExceller01

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