tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,913
- Office Version
- 365
- 2019
- Platform
- 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.
This is the code for adding borders:
Can someone please tell me whats wrong?
Thanks
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