Filling to end of page with borders / print area

mharper90

Board Regular
Joined
May 28, 2013
Messages
117
Office Version
  1. 365
Platform
  1. MacOS
I am using code to apply basic borders around all used cells in a worksheet. Perfectly, this applies borders to the anticipated range. I use the same range to set the print area. I'd like to modify the macro to modify this range so as to set the print area AND apply borders to all cells required to fill the page. In other words, if there are 15 rows, but a page could be 40, I want the print area set to row 40, and borders applied to the same range, so that when printed, it appears as a full page (with 25 blank rows of just borders). Then, if there are 50 rows, the macro should set the print area and borders to 80 rows, to completely fill 2 pages (with 30 blank rows of just borders).


Code:
ws.range("A1:E" & wsLr).borderaround
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi there, will each page always be 40 rows?

I'm not sure of the exact number, and the file is at work so I can't check right now. But the rows are consistent height, so whatever variable it is that equals a total page could easily be changed, I imagine. Judging from other projects I have, 40 is probably a good starting point.
 
Upvote 0
How about
Code:
Sub mharper90()
   Dim Lr As Long, Trws As Long
   
   Lr = Range("A" & Rows.count).End(xlUp).Row
   Trws = Application.RoundUp(Lr / 40, 0) * 40
   With Range("A1:E" & Trws)
      .Borders.Weight = xlThin
      .Parent.PageSetup.PrintArea = .Address
   End With
End Sub
 
Upvote 0

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