Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Automatic Selection of Portrait or Landscape.

Automatic Selection of Portrait or Landscape

by Allen Wyatt
(last updated June 25, 2016)

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. Select Custom Views from the View menu. Excel displays the Custom Views dialog box.
  3. Click on the Add button. Excel displays the Add View dialog box. (See Figure 1.)
  4. Figure 1. The Add View dialog box.

  5. In the Name field, supply the name you want associated with this view.
  6. 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.
  7. When you are satisfied with your settings, click the OK button. The current view is saved by Excel.
  8. Repeat steps 1 through 6, 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.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10364) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) 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

Using Very Long Worksheet Tab Names

Excel places a limit on how many characters you can use in a worksheet name. This tip discusses that limit and provides some ...

Discover More

Arranging Workbook Windows

If you find yourself working with a number of different workbooks at the same time, you may want to arrange your desktop so ...

Discover More

Specifying a Browser in a Hyperlink

Excel allows you to easily add hyperlinks to a worksheet. Click on it, and the target of the link is opened in a browser ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

MORE EXCELTIPS (MENU)

Changing Page Orientation

Page orientation controls the way in which information is printed on the page. Here's how you can control the page ...

Discover More

Flipping Landscape Orientation when Printing

When printing a worksheet, you may want to rotate the output on the page to fit a certain orientation. Excel doesn't allow ...

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 for this tip:

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 menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

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.

Links and Sharing
Share