Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? . |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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? . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Adding rows based on no of rows specified from a given position | Excel Worksheet Functions | |||
Adding new rows to an Excel spreadsheet | Charts and Charting in Excel | |||
Adding five new rows every 40 rows in a spreadsheet? | Excel Discussion (Misc queries) | |||
Adding Rows offsets to working rows across two worksheets | Setting up and Configuration of Excel | |||
Sum only adding rows on page instead of entire spreadsheet - help | Excel Discussion (Misc queries) |