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: Printing Based on Cell Contents.

Printing Based on Cell Contents

Written by Allen Wyatt (last updated November 15, 2021)
This tip applies to Excel 97, 2000, 2002, and 2003


2

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)
    Dim targCell As Range
    Set targCell = Worksheets(1).Range("B2")

    If Not Application.Intersect(Target, targCell) Is Nothing Then
        If targCell.Value = 1001 Then
            Worksheets(1).PrintOut
        End If
    End If
End Sub

This macro examines the contents of cell B2. If the cell contents are changed 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 (3832) 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: 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

Displaying ScreenTips

ScreenTips are those small, yellow boxes that appear when you hover over different objects in Word. You have complete ...

Discover More

Fixing the Decimal Point

Don't want to always type the decimal point as you enter information in a worksheet? If you are entering information that ...

Discover More

Noting the Workbook Creation Date

You may want to add, to your worksheet, the date on which a particular workbook was created. Excel doesn't provide a way ...

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (menu)

Printing Odd or Even Pages

When you print a worksheet, Excel normally prints all the pages or a consecutive series of pages that you specify. If you ...

Discover More

Printing to a Disk File

When printing a worksheet, there may be times when you want to send the printer output to a disk file instead of to the ...

Discover More

Hiding a Hyperlink on a Printout

Hyperlinks can be real handy in a workbook, but you may not always want them visible when you send the workbook to the ...

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 five more than 3?

2021-02-07 13:21:21

Willy Vanhaelen

Here is a 2 line code version of the first macro:

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


2018-06-29 14:45:33

chastity lamb

I need to know how to print rows only that have the word "print" in column G without using a filter. the sheet is protected.


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.

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.