Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Printing / September 2004

Tip: Looking for answers? Try searching our database.

Conditionally Change Print-Area

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Murtaza - 23 Sep 2004 05:00 GMT
How Can I conditionally change Print-Area...something like Conditional
Formula?

Background:
I have designed a template for a class-room to update the student's profile.
I will distribute this template to every Class-Teacher S/he will the
distribute among students. Initially, I have setup 8 columns.

Problem I faced while printing is that suppose some class have 5 students
some have 8 students or some have 12. How can i automatically setup
print-area (include or exclude the unnecessary columns in print-area)

Hope I will get some solution for this.

Regards,
Murtaza
Nick Hodge - 23 Sep 2004 18:55 GMT
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

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.