#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Print Area

Hi

I have data constantly changing from using 100 to 1500 lines and when it
comes to printing, I have to constantly set the print area or drag the print
preview handles. Is there a way that a piece of code can find the last
occupied cell in a column and have the page set up change accordingly?

Many thanks in advance

John
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Print Area

John,
With ActiveSheet
.PageSetup.PrintArea = .UsedRange.Address
End With

NickHK

"JohnUK" wrote in message
...
Hi

I have data constantly changing from using 100 to 1500 lines and when it
comes to printing, I have to constantly set the print area or drag the

print
preview handles. Is there a way that a piece of code can find the last
occupied cell in a column and have the page set up change accordingly?

Many thanks in advance

John



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Print Area

Hi Nick, thanks for your help.
I have tried it, but it doesnt work, maybe because I have formulas that run
down each side of the data that I want printed!!
John

"NickHK" wrote:

John,
With ActiveSheet
.PageSetup.PrintArea = .UsedRange.Address
End With

NickHK

"JohnUK" wrote in message
...
Hi

I have data constantly changing from using 100 to 1500 lines and when it
comes to printing, I have to constantly set the print area or drag the

print
preview handles. Is there a way that a piece of code can find the last
occupied cell in a column and have the page set up change accordingly?

Many thanks in advance

John




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Print Area

Hi John,

With ActiveSheet
.PageSetup.PrintArea =
intersect(.UsedRange.Address,range("a:b")).address
End With

Change "a:b" to be columns you want printed.

Regards,
Ivan

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Print Area

Hi Ivan - again

It comes back as a run time error - object required

Any ideas ?

John

"Ivan Raiminius" wrote:

Hi John,

With ActiveSheet
.PageSetup.PrintArea =
intersect(.UsedRange.Address,range("a:b")).address
End With

Change "a:b" to be columns you want printed.

Regards,
Ivan




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Print Area

Hi John,

sorry, should be:
intersect(.UsedRange,range("a:b")).address

Regards,
Ivan

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Print Area

John,
I'm sure Ivan will see it, but remove the .address from .usedrange.

NickHK

"JohnUK" wrote in message
...
Hi Ivan - again

It comes back as a run time error - object required

Any ideas ?

John

"Ivan Raiminius" wrote:

Hi John,

With ActiveSheet
.PageSetup.PrintArea =
intersect(.UsedRange.Address,range("a:b")).address
End With

Change "a:b" to be columns you want printed.

Regards,
Ivan




  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Print Area

Hi Nick,

thanks, you're right. And I already corrected myself (probably the post
was not visible to you as it takes some time to display)

Regards,
Ivan

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Print Area

Hi Ivan,

That worked, but I still have a problem and I think it has something to do
with my range's

The area I want to print is a pivot table along with some formulas that run
alongside, and because I need the formulas to refresh, I put them into a
range that goes up to 1500 lines. As an experiment I shrunk the range down to
500 lines, ran your code and walla the print area ended on the 500th line.

John

"Ivan Raiminius" wrote:

Hi John,

sorry, should be:
intersect(.UsedRange,range("a:b")).address

Regards,
Ivan


  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Print Area

Hi John,

try to reset last used cell with this:

Dim x As Long
x = ActiveWorksheet.UsedRange.Rows.Count

'and continue with setting printarea
With ActiveSheet
.PageSetup.PrintArea = intersect(.UsedRange,range("a:b")).address
End With

Regards,
Ivan



  #11   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Print Area

Sorry Ivan - being a pain again.

I tried it and got the run time again with Object Required

John

"Ivan Raiminius" wrote:

Hi John,

try to reset last used cell with this:

Dim x As Long
x = ActiveWorksheet.UsedRange.Rows.Count

'and continue with setting printarea
With ActiveSheet
.PageSetup.PrintArea = intersect(.UsedRange,range("a:b")).address
End With

Regards,
Ivan


  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Print Area

Hi John,

what line?

Regards,
Ivan

  #13   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Print Area

Stops on this:

x = ActiveWorksheet.UsedRange.Rows.count

John

"Ivan Raiminius" wrote:

Hi John,

what line?

Regards,
Ivan


  #14   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Print Area

Hi John,

rearange the code like this:

Dim x As Long
With ActiveSheet
x = .UsedRange.Rows.Count
.PageSetup.PrintArea = intersect(.UsedRange,range("a:b")).address
End With

Regards,
Ivan

  #15   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Print Area

Hi Ivan, thanks for your patience, but I think your going to give up on me,
because now I am back to where I was before. I entered your latest code but
the page setup still goes down to the end of the range and bypasses all the
data.
John

"Ivan Raiminius" wrote:

Hi John,

rearange the code like this:

Dim x As Long
With ActiveSheet
x = .UsedRange.Rows.Count
.PageSetup.PrintArea = intersect(.UsedRange,range("a:b")).address
End With

Regards,
Ivan




  #16   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 258
Default Print Area

Hi John,

let's try different attitude:

dim i as long
dim j as long
dim rng as range
set rng=range("b1..e1") ' 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.Ro ws.Count-rng.Row,1).end(xlup).row)
next i
activesheet.pagesetup.printarea =
rng.Resize(j-rng.row+1,rng.Columns.Count).Address

Change "b1..e1" in "set rng=range("b1..e1")" to be address of first row
of data you want to print.

Please let me know if it worked.

Regards,
Ivan

  #17   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Print Area

Fantastic - Ivan you are a star.

Many thanks - much appreciated - and thanks to Nick

Take care

Regards

John

"Ivan Raiminius" wrote:

Hi John,

let's try different attitude:

dim i as long
dim j as long
dim rng as range
set rng=range("b1..e1") ' 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.Ro ws.Count-rng.Row,1).end(xlup).row)
next i
activesheet.pagesetup.printarea =
rng.Resize(j-rng.row+1,rng.Columns.Count).Address

Change "b1..e1" in "set rng=range("b1..e1")" to be address of first row
of data you want to print.

Please let me know if it worked.

Regards,
Ivan


  #18   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Print Area

Using the example posted:

Assume your pivotTable is in B1:D200 and you have formulas pre-entered in
E1:E1500

this code only prints out B1:D200? Or are you not printing out the
pre-entered formulas? (Pivot Table actually in B1:E200 and formulas in
F1:F1500 as an example - then rng = Range("B1:E1"))

Just curious - because I don't see how this solves the problem you described
if you want to include the pre-entered formulas.

--
Regards,
Tom Ogilvy


"JohnUK" wrote:

Fantastic - Ivan you are a star.

Many thanks - much appreciated - and thanks to Nick

Take care

Regards

John

"Ivan Raiminius" wrote:

Hi John,

let's try different attitude:

dim i as long
dim j as long
dim rng as range
set rng=range("b1..e1") ' 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.Ro ws.Count-rng.Row,1).end(xlup).row)
next i
activesheet.pagesetup.printarea =
rng.Resize(j-rng.row+1,rng.Columns.Count).Address

Change "b1..e1" in "set rng=range("b1..e1")" to be address of first row
of data you want to print.

Please let me know if it worked.

Regards,
Ivan


  #19   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Print Area

Hi Tom,
Thanks for your input.
I wanted to print out some of the columns that contained formulas as well as
the pivot table and I think the line that contains
(application.Rows.Count-rng.Row,1) looks at the data in the first column
(ideal because of no formulas) and gives me what I am looking for.
However, I have tried to apply the same principle on a different page, but
this time not so easy and I think its because all the columns have formulas.
This is my poor way of trying to work around the problem:
I am trying to use code to enter a value into a different column so that
Toms code can do the same trick:

Range("E40").Select
If ActiveCell 0 Then
Range("N40").Select
ActiveCell.FormulaR1C1 = "1"

Range("E41").Select
If ActiveCell 0 Then
Range("N41").Select
ActiveCell.FormulaR1C1 = "1"

Range("E42").Select
If ActiveCell 0 Then
Range("N42").Select
ActiveCell.FormulaR1C1 = "1"

And so on and so on (I need 50 lines done this way)
I know you must be laughing at me right now, but can you see what I am
trying to do?
May I ask for your help?
Either there is another way altogether or can the above code be shortened
somewhat?

Regards

John


"Tom Ogilvy" wrote:

Using the example posted:

Assume your pivotTable is in B1:D200 and you have formulas pre-entered in
E1:E1500

this code only prints out B1:D200? Or are you not printing out the
pre-entered formulas? (Pivot Table actually in B1:E200 and formulas in
F1:F1500 as an example - then rng = Range("B1:E1"))

Just curious - because I don't see how this solves the problem you described
if you want to include the pre-entered formulas.

--
Regards,
Tom Ogilvy


"JohnUK" wrote:

Fantastic - Ivan you are a star.

Many thanks - much appreciated - and thanks to Nick

Take care

Regards

John

"Ivan Raiminius" wrote:

Hi John,

let's try different attitude:

dim i as long
dim j as long
dim rng as range
set rng=range("b1..e1") ' 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.Ro ws.Count-rng.Row,1).end(xlup).row)
next i
activesheet.pagesetup.printarea =
rng.Resize(j-rng.row+1,rng.Columns.Count).Address

Change "b1..e1" in "set rng=range("b1..e1")" to be address of first row
of data you want to print.

Please let me know if it worked.

Regards,
Ivan


  #20   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Print Area

oops sorry - I meant Ivan's code

"JohnUK" wrote:

Hi Tom,
Thanks for your input.
I wanted to print out some of the columns that contained formulas as well as
the pivot table and I think the line that contains
(application.Rows.Count-rng.Row,1) looks at the data in the first column
(ideal because of no formulas) and gives me what I am looking for.
However, I have tried to apply the same principle on a different page, but
this time not so easy and I think its because all the columns have formulas.
This is my poor way of trying to work around the problem:
I am trying to use code to enter a value into a different column so that
Toms code can do the same trick:

Range("E40").Select
If ActiveCell 0 Then
Range("N40").Select
ActiveCell.FormulaR1C1 = "1"

Range("E41").Select
If ActiveCell 0 Then
Range("N41").Select
ActiveCell.FormulaR1C1 = "1"

Range("E42").Select
If ActiveCell 0 Then
Range("N42").Select
ActiveCell.FormulaR1C1 = "1"

And so on and so on (I need 50 lines done this way)
I know you must be laughing at me right now, but can you see what I am
trying to do?
May I ask for your help?
Either there is another way altogether or can the above code be shortened
somewhat?

Regards

John


"Tom Ogilvy" wrote:

Using the example posted:

Assume your pivotTable is in B1:D200 and you have formulas pre-entered in
E1:E1500

this code only prints out B1:D200? Or are you not printing out the
pre-entered formulas? (Pivot Table actually in B1:E200 and formulas in
F1:F1500 as an example - then rng = Range("B1:E1"))

Just curious - because I don't see how this solves the problem you described
if you want to include the pre-entered formulas.

--
Regards,
Tom Ogilvy


"JohnUK" wrote:

Fantastic - Ivan you are a star.

Many thanks - much appreciated - and thanks to Nick

Take care

Regards

John

"Ivan Raiminius" wrote:

Hi John,

let's try different attitude:

dim i as long
dim j as long
dim rng as range
set rng=range("b1..e1") ' 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.Ro ws.Count-rng.Row,1).end(xlup).row)
next i
activesheet.pagesetup.printarea =
rng.Resize(j-rng.row+1,rng.Columns.Count).Address

Change "b1..e1" in "set rng=range("b1..e1")" to be address of first row
of data you want to print.

Please let me know if it worked.

Regards,
Ivan




  #21   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Print Area

Yes, your right. That whole loop ends up just giving you the used last row
in column A from what I can see. Not sure why the loop is even there.

--
Regards,
Tom Ogilvy


"JohnUK" wrote:

Hi Tom,
Thanks for your input.
I wanted to print out some of the columns that contained formulas as well as
the pivot table and I think the line that contains
(application.Rows.Count-rng.Row,1) looks at the data in the first column
(ideal because of no formulas) and gives me what I am looking for.
However, I have tried to apply the same principle on a different page, but
this time not so easy and I think its because all the columns have formulas.
This is my poor way of trying to work around the problem:
I am trying to use code to enter a value into a different column so that
Toms code can do the same trick:

Range("E40").Select
If ActiveCell 0 Then
Range("N40").Select
ActiveCell.FormulaR1C1 = "1"

Range("E41").Select
If ActiveCell 0 Then
Range("N41").Select
ActiveCell.FormulaR1C1 = "1"

Range("E42").Select
If ActiveCell 0 Then
Range("N42").Select
ActiveCell.FormulaR1C1 = "1"

And so on and so on (I need 50 lines done this way)
I know you must be laughing at me right now, but can you see what I am
trying to do?
May I ask for your help?
Either there is another way altogether or can the above code be shortened
somewhat?

Regards

John


"Tom Ogilvy" wrote:

Using the example posted:

Assume your pivotTable is in B1:D200 and you have formulas pre-entered in
E1:E1500

this code only prints out B1:D200? Or are you not printing out the
pre-entered formulas? (Pivot Table actually in B1:E200 and formulas in
F1:F1500 as an example - then rng = Range("B1:E1"))

Just curious - because I don't see how this solves the problem you described
if you want to include the pre-entered formulas.

--
Regards,
Tom Ogilvy


"JohnUK" wrote:

Fantastic - Ivan you are a star.

Many thanks - much appreciated - and thanks to Nick

Take care

Regards

John

"Ivan Raiminius" wrote:

Hi John,

let's try different attitude:

dim i as long
dim j as long
dim rng as range
set rng=range("b1..e1") ' 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.Ro ws.Count-rng.Row,1).end(xlup).row)
next i
activesheet.pagesetup.printarea =
rng.Resize(j-rng.row+1,rng.Columns.Count).Address

Change "b1..e1" in "set rng=range("b1..e1")" to be address of first row
of data you want to print.

Please let me know if it worked.

Regards,
Ivan


  #22   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Print Area

Possibly
for i = 1 to 50
if cells(i + 39) 0 then cells(i + 39,"N").Value = 1
Next


if you want to quit the first time the cell is not 0 then

for i = 1 to 50
if cells(i + 39) 0 then
cells(i + 39,"N").Value = 1
else
exit for
end if
Next

--
Regards,
Tom Ogilvy


"JohnUK" wrote:

Hi Tom,
Thanks for your input.
I wanted to print out some of the columns that contained formulas as well as
the pivot table and I think the line that contains
(application.Rows.Count-rng.Row,1) looks at the data in the first column
(ideal because of no formulas) and gives me what I am looking for.
However, I have tried to apply the same principle on a different page, but
this time not so easy and I think its because all the columns have formulas.
This is my poor way of trying to work around the problem:
I am trying to use code to enter a value into a different column so that
Toms code can do the same trick:

Range("E40").Select
If ActiveCell 0 Then
Range("N40").Select
ActiveCell.FormulaR1C1 = "1"

Range("E41").Select
If ActiveCell 0 Then
Range("N41").Select
ActiveCell.FormulaR1C1 = "1"

Range("E42").Select
If ActiveCell 0 Then
Range("N42").Select
ActiveCell.FormulaR1C1 = "1"

And so on and so on (I need 50 lines done this way)
I know you must be laughing at me right now, but can you see what I am
trying to do?
May I ask for your help?
Either there is another way altogether or can the above code be shortened
somewhat?

Regards

John


"Tom Ogilvy" wrote:

Using the example posted:

Assume your pivotTable is in B1:D200 and you have formulas pre-entered in
E1:E1500

this code only prints out B1:D200? Or are you not printing out the
pre-entered formulas? (Pivot Table actually in B1:E200 and formulas in
F1:F1500 as an example - then rng = Range("B1:E1"))

Just curious - because I don't see how this solves the problem you described
if you want to include the pre-entered formulas.

--
Regards,
Tom Ogilvy


"JohnUK" wrote:

Fantastic - Ivan you are a star.

Many thanks - much appreciated - and thanks to Nick

Take care

Regards

John

"Ivan Raiminius" wrote:

Hi John,

let's try different attitude:

dim i as long
dim j as long
dim rng as range
set rng=range("b1..e1") ' 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.Ro ws.Count-rng.Row,1).end(xlup).row)
next i
activesheet.pagesetup.printarea =
rng.Resize(j-rng.row+1,rng.Columns.Count).Address

Change "b1..e1" in "set rng=range("b1..e1")" to be address of first row
of data you want to print.

Please let me know if it worked.

Regards,
Ivan


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
set area in excel not giving me option to set print area? J Littlebear Excel Discussion (Misc queries) 4 April 23rd 23 09:04 PM
File, print area, clear area, is not working cblind New Users to Excel 2 September 12th 07 04:51 PM
print area across the freeze panes area tom Excel Worksheet Functions 2 January 6th 07 05:23 PM
Macro - Set Print Area for Changing Data Area ksp Excel Programming 5 May 15th 06 10:20 PM
How do you turn off a print area for a page? (no print area) Grunen Excel Discussion (Misc queries) 4 October 8th 05 07:46 PM


All times are GMT +1. The time now is 02:08 PM.

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"