View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Per Jessen[_2_] Per Jessen[_2_] is offline
external usenet poster
 
Posts: 703
Default Print only down to last occupied row

On 25 Nov., 11:46, "mepetey" wrote:
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