Murtaza
You could use the Workbook_BeforePrint() event like so
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim lLastRow As Long, iLastCol As Integer
lLastRow = ActiveSheet.Range("A65536").End(xlUp).Row
iLastCol = ActiveSheet.Range("IV1").End(xlToLeft).Column
ActiveSheet.PageSetup.PrintArea = Range(Cells(1, 1), Cells(lLastRow,
iLastCol)).Address
End Sub

Signature
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS
> How Can I conditionally change Print-Area...something like Conditional
> Formula?
[quoted text clipped - 13 lines]
> Regards,
> Murtaza
David McRitchie - 26 Sep 2004 03:44 GMT
Hi Murtaza,
I think I would modify Nicks subroutine. Nick's is a workbook event
macro so it will make the same assumptions for print area for each
sheet in the workbook, unless you check the worksheet name..
If these sheets are the only sheets in the workbook then Nick's
use of WorkbookBeforePrint is fine, change the 1st line of my
modifications back to
Private Sub Workbook_BeforePrint(Cancel As Boolean)
and install in ThisWorkBook ;
otherwise, I would suggest the following:
Print Area based on Column A for height and lastcell for width
Any manual change to a cell will change the print area.
To install rightclick on the sheet tab, view code, insert the following
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lLastRow As Long, iLastCol As Long 'Nick Hodge/D.McR, 2004-09-25 printing
lLastRow = Cells(Rows.Count, 1).End(xlUp).Row
iLastCol = Cells.SpecialCells(xlLastCell).Column
ActiveSheet.PageSetup.PrintArea = _
Range(Cells(1, 1), Cells(lLastRow, iLastCol)).Address
End Sub
As a template it would be better if you can use the workbook_beforeprint
since you wouldn't have to worry about template sheets befing different
than for other workbooks, but you would have to be sure that is is good
for all worksheets in the workbook.
.
Note both row and column should be Long, on general principles
even though Excel only currently supports 256 columns since it's
inception coding and coding practices may become outdated
during the life of workbooks or their authors.
---
HTH,
David McRitchie, Microsoft MVP - Excel [site changed Nov. 2001]
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm
Search Page: http://www.mvps.org/dmcritchie/excel/search.htm
> Murtaza
>
[quoted text clipped - 25 lines]
> > Regards,
> > Murtaza