Print only down to last occupied row

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.
 
P

Per Jessen

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
 
E

excelent

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


"mepetey" skrev:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top