ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Changing Print area (https://www.excelbanter.com/excel-programming/297087-changing-print-area.html)

JT[_2_]

Changing Print area
 
I have a spreadsheet and I want the macro to set the print
area for me each time since the amount of data will be
chaning on a regular basis. I have the following from
using the macro recorder but it is not working. The macro
recorder hardcoded the cell addresses based on the current
data. I'm trying to change it to change the print area to
the selected cells. Any suggestions would be
appreciated. Here's the code I tried:

Sub Print_Area()

Range("A1").Select

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select

(The above lines properly select the data I want. The
following line is where I have the problem. I just don't
know the proper syntax.)

ActiveSheet.PageSetup.PrintArea = Selection

End Sub

Thanks for the help.

Bob Flanagan

Changing Print area
 
Try:

ActiveSheet.PageSetup.PrintArea = Selection.Address

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel

"JT" wrote in message
...
I have a spreadsheet and I want the macro to set the print
area for me each time since the amount of data will be
chaning on a regular basis. I have the following from
using the macro recorder but it is not working. The macro
recorder hardcoded the cell addresses based on the current
data. I'm trying to change it to change the print area to
the selected cells. Any suggestions would be
appreciated. Here's the code I tried:

Sub Print_Area()

Range("A1").Select

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select

(The above lines properly select the data I want. The
following line is where I have the problem. I just don't
know the proper syntax.)

ActiveSheet.PageSetup.PrintArea = Selection

End Sub

Thanks for the help.




Orf Bartrop

Changing Print area
 
Bob, perhaps you can help. I tried to use the code below but it does not
select the area I want to print.

I need to print from cell A1 to (and including) the last row of data. I
have additional rows of formatting after that but I do not want to print
those.

Orf Bartrop

Bob Flanagan wrote:

Try:

ActiveSheet.PageSetup.PrintArea = Selection.Address

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel

"JT" wrote in message
...


I have a spreadsheet and I want the macro to set the print
area for me each time since the amount of data will be
chaning on a regular basis. I have the following from
using the macro recorder but it is not working. The macro
recorder hardcoded the cell addresses based on the current
data. I'm trying to change it to change the print area to
the selected cells. Any suggestions would be
appreciated. Here's the code I tried:

Sub Print_Area()

Range("A1").Select

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select

(The above lines properly select the data I want. The
following line is where I have the problem. I just don't
know the proper syntax.)

ActiveSheet.PageSetup.PrintArea = Selection

End Sub

Thanks for the help.










All times are GMT +1. The time now is 04:34 PM.

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