Forum Discussion
Setting print area in a macro
- May 18, 2020
In this case, you need to create a variable (I've named mine rngPrint) and assign the end of the active cells to it. Then, you can assign the PrintArea based on the address of the variable you've created.
Code snippet is below.
Dim rngPrint As Range
Range("A1").Select
Set rngPrint = Range(Selection, ActiveCell.SpecialCells(xlLastCell)) 'This was the Ctrl-End
ActiveSheet.PageSetup.PrintArea = rngPrint.Address
In this case, you need to create a variable (I've named mine rngPrint) and assign the end of the active cells to it. Then, you can assign the PrintArea based on the address of the variable you've created.
Code snippet is below.
Dim rngPrint As Range
Range("A1").Select
Set rngPrint = Range(Selection, ActiveCell.SpecialCells(xlLastCell)) 'This was the Ctrl-End
ActiveSheet.PageSetup.PrintArea = rngPrint.Address
- LonnieCurrierMay 18, 2020Copper Contributor
Thank you macrordinary . That worked very well. 🙂