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

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
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,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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