Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. 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: Printing Based on Cell Contents.

Printing Based on Cell Contents

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


Theresa wonders if there is a way to format a cell so that if the contents of the cell meet certain criteria then a specific worksheet is automatically printed. The short answer is no, there is no way to use formatting to achieve this goal. You can, however, use an event handler macro to do the printing.

For example, one of the event handlers supported by Excel is triggered every time something in the workbook is changed. You can create an event handler that examines which cell was changed. If it is a specific cell, and if that cell contains a particular value, then a worksheet can be printed.

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$B$2" Then
        If Target.Value = 1001 Then
            Worksheets(1).PrintOut
        End If
    End If
End Sub

This macro examines which cell was changed. If it was cell B2 and if the cell contains the value 1001, then the worksheet is automatically printed.

Of course, you may want the contents of a particular cell to control what is printed when someone actually chooses to print. For instance, if the user chooses to print, you may want to examine the contents of a cell (such as E2) and, based on the contents of that cell, automatically modify what is printed. The following macro takes this approach:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Application.EnableEvents = False
    Select Case Worksheets("Sheet1").Range("E1")
        Case 1
            Worksheets("Sheet1").PrintOut
        Case 2
            Worksheets("Sheet2").PrintOut
        Case 3
            Worksheets("Sheet3").PrintOut
        Case 4
            Worksheets("Sheet4").PrintOut
        Case Else
            ActiveSheet.PrintOut
    End Select
    Cancel = True
    Application.EnableEvents = True
End Sub

The macro prints Sheet1, Sheet2, Sheet3, or Sheet4 depending on whether cell E2 contains 1, 2, 3, or 4.

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 (11578) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Printing Based on Cell Contents.

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

Viewing Your Entire Document Width

The Zoom tool is very useful to help you see all of your document information. Here's how to make sure you can see all ...

Discover More

Selecting a Table

There are several different ways you can select an entire table in Word. The various methods and shortcuts are described ...

Discover More

Using a Protected Worksheet

If you have a worksheet protected, it may not be immediately evident that it really is protected. This tip explains some ...

Discover More

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!

More ExcelTips (ribbon)

Specifying an Order for Page Printing

If a printout of your worksheet requires multiple pages, you may want to specify the order in which Excel prints those ...

Discover More

Printing a Portion of a Worksheet

Need to print a portion of a worksheet, but don't want to waste paper by printing the whole thing? It's easy to print ...

Discover More

Printing a Short Selection

Need to print just a portion of a worksheet? It's easy to do if you follow the steps in this tip.

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 two less than 9?

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.