Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Print Area Range Selection

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default Print Area Range Selection

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Print Area Range Selection

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
excel, worksheet, set print area, position selection on printed pa Eve Allen New Users to Excel 1 January 2nd 09 05:06 AM
How do I clear a print area when the selection is grayed out? Ron Excel Discussion (Misc queries) 0 July 24th 07 11:28 PM
print area selection slows excel, formula for hiding rows?? sbrimley Excel Discussion (Misc queries) 1 March 21st 06 11:26 PM
set print area based on selection crombes Excel Programming 0 November 2nd 05 07:15 PM
set print area based on selection crombes[_2_] Excel Programming 0 November 2nd 05 07:15 PM


All times are GMT +1. The time now is 09:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"