Using a Macro to Set a Print Range

Written by Allen Wyatt (last updated December 5, 2020)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and 2021


Grahame has a cell (C7) that contains a range, such as B8:B207. Whenever the range changes in C7, he needs a way to change the print range to match what is in that cell. However, Grahame is unsure of how to set the print range within the macro code.

Setting a print range within a macro is quite easy; you can do it in this manner:

ActiveSheet.PageSetup.PrintArea = "$A$1:$D$23"

Note that all you need to do is to assign to the PrintArea property a range that you want used for your print range. Thus, if cell C7 contains a range (like B8:B207), you could do it in this manner:

ActiveSheet.PageSetup.PrintArea = Range("C7").Value

You can, if you desire, create an event handler that will change the print area every time that cell C7 is changed. To do so, just add this to the VBA module for the worksheet. (Just right-click the sheet tab and choose View Code, then add the macro there.)

Private Sub Worksheet_Change(ByVal Target As Range)
    On Error Resume Next
    If Target.Address = "$C$7" Then
        ActiveSheet.PageSetup.PrintArea = Target.Value
    End If
End Sub

The Worksheet_Change event handler is automatically run every time there is a change in the worksheet. If the cell being changed is C7, then the PrintArea property is updated to reflected whatever is in cell C7.

Even though Grahame asked for how to set the print range in a macro, it should be noted that you can automatically set the print range without using a macro.

  1. Press Ctrl+F3. Excel displays the Name Manger dialog box.
  2. Click New. Excel displays the New Name dialog box.
  3. In the Name field, enter the following as a name: Print_Area
  4. Using the Scope drop-down list, choose the worksheet that contains the cell (C7) that contains the print range.
  5. In the Refers To field, enter the following formula: =INDIRECT(Sheet1!$C$7)
  6. Click OK.

Now, anytime you print, the print range will be grabbed from whatever is in cell C7. Note that you should change the formula, in step 5, to use whatever sheet name you specified in step 4. (In place of the Sheet1 sheet used in the example.)

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13807) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Reading a PDF Newsletter on a Cell Phone

Sometimes creating a Word document is just the first step. Often you'll want to then convert it to a PDF file that can be ...

Discover More

Inserting the Date in a Header or Footer

Need today's date in the header or footer of your document? Here's how to get it there easily.

Discover More

Collating Copies

When you print multiple copies of worksheets that require more than one page each, you'll probably want those copies ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Setting Print Ranges for Multiple Worksheets

Need the same print range set for different worksheets in the same workbook? It can't be done in one step manually, but ...

Discover More

Dynamically Setting a Print Area

You can define, in your worksheet, an area that you want printed. If you want this print area to be dynamic, based on the ...

Discover More

Clearing the Print Area

Excel allows you to specify which portions of a worksheet should be printed when you send output to your printer. If you ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 0 + 7?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.