Forum

Macro to exclude th...
 
Notifications
Clear all

Macro to exclude the page Header

5 Posts
2 Users
0 Reactions
62 Views
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

A macro to exclude the page Header  from the last page in the Excel report.

Because this can be helpful when we want to include a summary page in the report  but the Header should appear in each page but not the last page of the report.

 
Posted : 04/06/2019 8:20 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi David,

Can you put the summary page at the start?  You can have a different header for the first page.

Phil

 
Posted : 05/06/2019 12:41 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Sub RepeatRowsExceptLastPage()
Dim xPages As Long, I As Integer, xRg As Range
On Error Resume Next
xPages = ActiveSheet.PageSetup.Pages.Count
Set xRg = Rows("18:19")     ' that the rows I want to repeat in each page but not the last page
If xRg Is Nothing Then Exit Sub
On Error Resume Next

   If xPages > 0 Then
            With ActiveSheet.PageSetup
             .PrintTitleRows = xRg.AddressLocal
            ActiveSheet.PrintOut from:=0, To:=xPages - 1
           .PrintTitleRows = ""
           ActiveSheet.PrintOut from:=xPages
           End With
    End If
 End Sub

 

The above VB does work but split the output files into two files, don't know why? Pls help to debug

 
Posted : 05/06/2019 1:45 am
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

David,

Can't debug it without your workbook.

Regards

Phil

 
Posted : 05/06/2019 5:09 am
(@david_ng)
Posts: 310
Reputable Member
Topic starter
 

Thanks Philip, I manage to resolve it. so pls close this case.

 
Posted : 06/06/2019 1:18 am
Share: