ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Adding new rows to spreadsheet (https://www.excelbanter.com/excel-programming/285806-adding-new-rows-spreadsheet.html)

Roy[_5_]

Adding new rows to spreadsheet
 
Here's a scenario:

I have a macro that prints the range a1:c52. I then add
a few rows within this range. How do I get the macro to
adjust the print range to include the new range?

Tom Ogilvy

Adding new rows to spreadsheet
 
Range("A1").CurrentRegion.Printout

--
Regards,
Tom Ogilvy

"Roy" wrote in message
...
Here's a scenario:

I have a macro that prints the range a1:c52. I then add
a few rows within this range. How do I get the macro to
adjust the print range to include the new range?




Nick Hodge

Adding new rows to spreadsheet
 
Roy

Making an assumption that the column will only extend to C the code below
finds the last row with data. Goes to row 65536 and looks up in columnA and
uses this to set the print area to that address.

You can use the relevant parts in your code

Sub setprintrange()
Dim lLastRow As Long
lLastRow = Range("A65536").End(xlUp).Row
Worksheets("Sheet1").PageSetup.PrintArea = Range("A1:C" & lLastRow).Address
End Sub

If the column differs you could use other methods in place of this. This
example from help
This example sets the print area to the current region on Sheet1. Note

that you use the Address property to return an A1-style address.

Worksheets("Sheet1").Activate
ActiveSheet.PageSetup.PrintArea = _
ActiveCell.CurrentRegion.Address


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
HIS



Roy wrote:
Here's a scenario:

I have a macro that prints the range a1:c52. I then add
a few rows within this range. How do I get the macro to
adjust the print range to include the new range?




Roy[_5_]

Adding new rows to spreadsheet
 
Thanks for your help.
-----Original Message-----
Roy

Making an assumption that the column will only extend to

C the code below
finds the last row with data. Goes to row 65536 and

looks up in columnA and
uses this to set the print area to that address.

You can use the relevant parts in your code

Sub setprintrange()
Dim lLastRow As Long
lLastRow = Range("A65536").End(xlUp).Row
Worksheets("Sheet1").PageSetup.PrintArea = Range("A1:C"

& lLastRow).Address
End Sub

If the column differs you could use other methods in

place of this. This
example from help
This example sets the print area to the current

region on Sheet1. Note
that you use the Address property to return an A1-style

address.

Worksheets("Sheet1").Activate
ActiveSheet.PageSetup.PrintArea = _
ActiveCell.CurrentRegion.Address


--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England




Roy wrote:
Here's a scenario:

I have a macro that prints the range a1:c52. I then

add
a few rows within this range. How do I get the macro

to
adjust the print range to include the new range?



.


Roy[_5_]

Adding new rows to spreadsheet
 
Thanks for your help.
-----Original Message-----
Range("A1").CurrentRegion.Printout

--
Regards,
Tom Ogilvy

"Roy" wrote in

message
...
Here's a scenario:

I have a macro that prints the range a1:c52. I then

add
a few rows within this range. How do I get the macro

to
adjust the print range to include the new range?



.



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com