Forum Discussion

LonnieCurrier's avatar
LonnieCurrier
Copper Contributor
May 18, 2020
Solved

Setting print area in a macro

How can I automatically set the print area in a macro? I recorded a macro that saved the workbook, selected the cells that contained data (by selecting cell A1, then pressing Ctrl-End to go to the “L...
  • macrordinary's avatar
    May 18, 2020

    LonnieCurrier 

    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

Resources