Dynamically Setting a Print Area

Written by Allen Wyatt (last updated December 21, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


1

Travis has a cell that, through a series of formulas, contains the upper-left corner of a 5 column by 20 row area that needs to be printed. For instance, if the cell contains $F$15, then the print area would be F15:J34, but if it contained $D$45, then the print area would be D45:H64. Travis wonders if it is possible to dynamically set the print area based on the contents of the cell, without using a macro.

Yes, there is a way you can set a dynamic print area without using a macro. Let's assume for the purposes of this tip that the calculated cell address is in A1. In preparation, you need to set up a print area:

  1. Select a random cell or range of cells; it doesn't really matter at this point.
  2. Display the Page Layout tab of the ribbon.
  3. Click the Print Area tool. Excel displays two options.
  4. Choose the Set Print Area option.

When you set a print area in this manner, Excel creates a named range called Print_Area. Whatever range it refers to is what will be printed when you choose to print. Since it is a named range, you can modify it in the Name Manager. Follow these steps to make the print area dynamic:

  1. Press Ctrl+F3. Excel displays the Name Manger.
  2. If there is more than one named range, select the Print_Area name.
  3. Click the Edit button. Excel displays the Edit Name dialog box. (See Figure 1.)
  4. Figure 1. The Edit Name dialog box.

  5. In the Refers To box, at the bottom of the dialog box, replace whatever is there with the following formula. (If the name of the worksheet is different from what is shown in this formula, make the necessary change to reflect reality.)
  6. =OFFSET(INDIRECT(Sheet1!$A$1),,,20,5)
    
  7. Click OK to close the Edit Name dialog box.
  8. Click OK again to close the Name Manager.

That's it. Your print area is now dynamic, dependent on the address stored in cell A1.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13946) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, 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

Problem Printing Quotation Marks

If you go to print a document and find out that your quotation marks aren't printing properly, there could be a number of ...

Discover More

Creating a String

Need to use a macro to create a text string? One easy way to do it is to use the String function, described in this tip.

Discover More

Replacing Tildes at the Beginning of a Cell

Replacing a specific character (such as a tilde) seems a simple task, until you need to replace it only in a certain ...

Discover More

Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!

More ExcelTips (ribbon)

Setting the Print Area

Many people, when they print a worksheet, print the entire thing. You don't have to, however. You can specify that Excel ...

Discover More

Copying Print Areas when Copying Worksheets

Print areas are a great way to define what, exactly, you want to print from a worksheet. When you copy worksheets, the ...

Discover More

Multiple Print Areas on a Single Printed Page

Want to print small, non-contiguous areas of your worksheet all on a single page? You might think that defining a ...

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 three minus 2?

2024-12-21 13:22:01

Tomek

I like the solution presented in this tip (I suggested this approach in my reply to help-wanted, but I probably wasn’t the only one). It is relatively simple, does what Travis wanted, and does not “contaminate” the spreadsheet with helper cells. What Allen did not mention was that the address of the cell A1 in the formula must be entered as an absolute address, i.e., Sheet1! $A$1; if it is entered as the relative address the Print_Area is not set properly, and the approach does not work (why? – I don’t know).

I also suggested another approach, that may not be as elegant, but potentially may have additional advantages. The steps are as follows:
1. Select a 20-rows by 5-columns range somewhere on the sheet, where it would not interfere with your data. Set the Print Area to that range.
2. In the top left corner of that print area enter =OFFSET(INDIRECT($A$1),0,0,20,5). This formula will spill and populate Print_Area with a copy of what you want to print, and when you print the sheet, it is what will be printed. As in the tip, I assume that the calculated cell address is in A1.
3. If using an older version of Excel that does not automatically spill into Array, you will need to enter the above formula as an Array Formula (Ctrl+Shift+<ENTER>) covering the whole Print_Area range.

The benefit of this approach is that you can format the data that is in the Print_Area any way you want, independently of the format of original data. Additionally, you can add rows above to add column labels and possibly the title, and add a column to the left for row labels. Those do not have to be static but can also depend on the content of A1. If you add rows and columns, obviously you will need to adjust the print area to include them as well.

There is one disadvantage of this approach: if any of the original cells are blank, they will show in the print area as zeros, probably not what you would want. It can be easily overcome by slight modification of the formula entered in step 2 as follows:
=IF(OFFSET(INDIRECT($A$1),0,0,20,5)="","",OFFSET(INDIRECT($A$1),0,0,20,5))
See screenshots of my test workbook (see Figure 1 below) (see Figure 2 below)

Figure 1. Source Data

Figure 2. Formatted Print Area


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.