Set bottom border of page to print

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,832
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I am trying to print a sheet and add borders at every page break.

In the code below, Increment specifies the number of rows per page.

Everything works if Increment is any number other than 1.

If Increment is 1, the bottom border on the page does not show.

However, if this line is omitted, the bottom border does show, regardless what Increment is set to.

Code:
Sheet1.HPageBreaks.Add Before:=Sheet1.Rows(Ticker)


Code:
Option Explicit

Sub Setup()
    
     Dim Increment As Long
     
     Increment = 1 '********************** CHANGE TO SUIT
     
     With wksInvoice
          
         .PageSetup.PrintArea = vbNullString
     
         .ResetAllPageBreaks
     
     End With
     
     ActiveWindow.View = xlPageBreakPreview
     
     Dim Setuprng As Range
      
     With wksInvoice
         
         Set Setuprng = .Range("A1:M100")
     
         With .PageSetup
         
             .PrintArea = Setuprng.Address
             
             .FitToPagesTall = Application.RoundUp(100 / Increment, 0)
         
             .FitToPagesWide = 1
         
         End With
         
         Set Setuprng = Nothing
     
         .VPageBreaks(1).DragOff Direction:=xlToRight, RegionIndex:=1
         
     End With
     
     NumRows = Sheet1.Range("End Row").Row - 10
     
     Dim Ticker As Long
     
     For Ticker = 10 + Increment To 10 + NumRows - 1 Step Increment
         
         Sheet1.HPageBreaks.Add Before:=Sheet1.Rows(Ticker) '************************* LINE WITH PROBLEM
         
         Call AddBorders(Ticker:=Ticker,  Increment:=Increment)
         
     Next Ticker
    
     ActiveWindow.View = xlNormalView
    
     wksInvoice.PrintOut
         
     With wksInvoice
          
         .PageSetup.PrintArea = vbNullString
     
         .ResetAllPageBreaks
     
     End With
        
End Sub

This is the code for adding borders:

Code:
Sub AddBorders(ByRef Ticker As Long, ByRef Increment As Long)

    With Sheet1

        Set rng = .Range(.Cells(Ticker - 1, 1), .Cells(Ticker - 1, 13))

    End With

    With rng

        .Borders(xlDiagonalDown).LineStyle = xlNone
        .Borders(xlDiagonalUp).LineStyle = xlNone

        With .Borders(xlEdgeLeft)

            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium

        End With

        Select Case Increment

            Case 1
                
                With .Borders(xlEdgeTop)

                    .LineStyle = xlContinuous
                    .ColorIndex = 0
                    .TintAndShade = 0
                    .Weight = xlMedium

                End With
                
            Case Else
                
                .Borders(xlEdgeTop).LineStyle = xlNone
                
        End Select
        
        With .Borders(xlEdgeBottom)

            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium

        End With

        With .Borders(xlEdgeRight)

            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlMedium

        End With

        .Borders(xlInsideVertical).LineStyle = xlNone
        .Borders(xlInsideHorizontal).LineStyle = xlNone

    End With

End Sub

Can someone please tell me whats wrong?

Thanks
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,214,641
Messages
6,120,695
Members
448,979
Latest member
DET4492

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