Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Automatic Selection of Portrait or Landscape.

Automatic Selection of Portrait or Landscape

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


Barbara has a worksheet that she needs to print out periodically. Sometimes she needs to only print three columns of data and other times she needs to print more. When she prints only three columns they fit very nicely on a page printed in portrait orientation. When she prints more columns then she needs to print in landscape orientation. Barbara wonders if there is a way she can set up Excel so that it automatically switches from portrait to landscape based upon the number of columns she wants to print.

Perhaps the easiest way to handle this type of printing is to add a little macro that runs just before printing. If the print area is set so that it contains 1, 2, or 3, columns, then the printout is done in portrait orientation. Any other number of columns and landscape orientation is used. Here is the macro; you should add it to the ThisWorkbook module:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    With ActiveSheet.PageSetup
        If Range(.PrintArea).Columns.Count > 3 Then
            .Orientation = xlLandscape
        Else
            .Orientation = xlPortrait
        End If
    End With
End Sub

Of course, it may be more beneficial (and flexible) if you simply use the Custom Views feature of Excel. You can specify a view that includes your three columns or any number of columns you want. You can even have the view include print settings, so the orientation of the page would be included in the view. Follow these steps to set up the views:

  1. Format and situate your worksheet as you want it to appear. Make sure, as well, that you set both the print area for your three columns and set the page layout to portrait orientation.
  2. Display the View tab of the ribbon.
  3. Click Custom Views in the Workbook Views group. Excel displays the Custom Views dialog box.
  4. Click on the Add button. Excel displays the Add View dialog box. (See Figure 1.)
  5. Figure 1. The Add View dialog box.

  6. In the Name field, supply the name you want associated with this view.
  7. In the View Includes section, select the options that reflect what you want saved with this view. Make sure you specify that you want to include print settings.
  8. When you are satisfied with your settings, click the OK button. The current view is saved by Excel.
  9. Repeat steps 1 through 7, but this time for your larger print area, making sure you set the page layout for landscape orientation.

Now, whenever you want to print different ways, you just call up the view you want and choose to print—everything else is already set for you.

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 (10365) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Automatic Selection of Portrait or Landscape.

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

Returning a Worksheet Name

Need to know the name of the current worksheet? You can use the CELL function as the basis for finding this information ...

Discover More

Turning Off Insert Options

When you insert rows, columns, or cells in a worksheet, does the resulting Insert Options icon bother you? Here's how to ...

Discover More

Using the MROUND Worksheet Function

If you want to round a value to some multiple of a whole number, you'll want to become familiar with the MROUND function. ...

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)

Selecting a Paper Size

Excel can print your worksheet on just about any paper size you can imagine. How you select the paper size you want used ...

Discover More

Printing an Entire Workbook by Default

Need to print an entire workbook? It's as easy as adding a single line of code to your macros.

Discover More

Repeating Rows on a Printout Except On the Last Page

When setting up a worksheet for printing, you can specify that Excel repeat some of your rows at the top of each page ...

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 four minus 0?

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.