Print only down to last occupied row

  • Thread starter Thread starter mepetey
  • Start date Start date
M

mepetey

Need a little help please guys, I have a worksheet that, after running
filters, presents me with the data I actually need. Trouble is the list
varies in length on each run. It's a pain to keep manually changing the
print area. Can anyone help with a routine to set the print area down to the
last "occupied" row?

Any help greatly appreciated.
 
Need a little help please guys, I have a worksheet that, after running
filters, presents me with the data I actually need. Trouble is the list
varies in length on each run. It's a pain to keep manually changing the
print area. Can anyone help with a routine to set the print area down to the
last "occupied" row?

Any help greatly appreciated.

Put the code in the codesheet for ThisWorkbook.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
FirstCell = "A1"
LastCell = Range("A1").End(xlDown).End(xlToRight).Address
ActiveSheet.PageSetup.PrintArea = Range(FirstCell, LastCell).Address
End Sub

Regards,

Per
 
Range(Range("A1"), ActiveCell.SpecialCells(xlLastCell)).Select
ActiveSheet.PageSetup.PrintArea = Selection.Address


"mepetey" skrev:
 
Back
Top