Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I am trying to set the print area in a macro. I have varying lines of data
and the last column of data does not contain the last row of data. In the code below, which I copied in a previous post from Ivan Raiminius, how do I add 3 rows to my range so that the print area will include all my data? Sub PrintArea() ' ' PrintArea Macro ' Macro recorded 11/20/2008 by Network Administrator ' ' Dim i As Long Dim j As Long Dim rng As Range Set rng = Range("a1..n1") ' the address of first row of data you want to Print out j = 0 For i = 1 To rng.Columns.Count j = WorksheetFunction.Max(j, rng.Cells(Application.Rows.Count - rng.Row, 1).End(xlUp).Row) Next i ActiveSheet.PageSetup.PrintArea = rng.Resize(j - rng.Row + 1, rng.Columns.Count).Address End Sub Thanks so much for your help.. -- www.bardpv.com Tempe, Arizona |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
i would say, change this:
ActiveSheet.PageSetup.PrintArea = rng.Resize(j - rng.Row + 1, rng.Columns.Count).Address to this ActiveSheet.PageSetup.PrintArea = rng.Resize(j - rng.Row + 4, rng.Columns.Count).Address that would add 3 more rows. :) susan On Nov 20, 12:34*pm, Emma Aumack wrote: I am trying to set the print area in a macro. *I have varying lines of data and the last column of data does not contain the last row of data. *In the code below, which I copied in a previous post from Ivan Raiminius, how do I add 3 rows to my range so that the print area will include all my data? Sub PrintArea() ' ' PrintArea Macro ' Macro recorded 11/20/2008 by Network Administrator ' ' Dim i As Long Dim j As Long Dim rng As Range Set rng = Range("a1..n1") ' the address of first row of data you want to Print out j = 0 For i = 1 To rng.Columns.Count j = WorksheetFunction.Max(j, rng.Cells(Application.Rows.Count - rng.Row, 1).End(xlUp).Row) Next i ActiveSheet.PageSetup.PrintArea = rng.Resize(j - rng.Row + 1, rng.Columns.Count).Address End Sub Thanks so much for your help.. --www.bardpv.com Tempe, Arizona |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'd suggest a slightly different approach:
Sub SetPrintArea() Dim Rng As Range Dim LastCell As Range Set Rng = Range("a1:n1") ' the address of first row of data you want to Set LastCell = Rng.EntireColumn.Find("*", Rng.Cells(1), , , , xlPrevious) Rng.Resize(LastCell.Row - Rng.Row + 1).Name = "Print_Area" End Sub -- Jim "Emma Aumack" wrote in message ... |I am trying to set the print area in a macro. I have varying lines of data | and the last column of data does not contain the last row of data. In the | code below, which I copied in a previous post from Ivan Raiminius, how do I | add 3 rows to my range so that the print area will include all my data? | | Sub PrintArea() | ' | ' PrintArea Macro | ' Macro recorded 11/20/2008 by Network Administrator | ' | | ' | Dim i As Long | Dim j As Long | Dim rng As Range | Set rng = Range("a1..n1") ' the address of first row of data you want to | Print out | j = 0 | For i = 1 To rng.Columns.Count | j = WorksheetFunction.Max(j, rng.Cells(Application.Rows.Count - rng.Row, | 1).End(xlUp).Row) | Next i | ActiveSheet.PageSetup.PrintArea = rng.Resize(j - rng.Row + 1, | rng.Columns.Count).Address | | End Sub | | Thanks so much for your help.. | | -- | www.bardpv.com | Tempe, Arizona |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
excel, worksheet, set print area, position selection on printed pa | New Users to Excel | |||
How do I clear a print area when the selection is grayed out? | Excel Discussion (Misc queries) | |||
print area selection slows excel, formula for hiding rows?? | Excel Discussion (Misc queries) | |||
set print area based on selection | Excel Programming | |||
set print area based on selection | Excel Programming |