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

by Allen Wyatt
(last updated June 4, 2015)


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
        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
        Case 2
        Case 3
        Case 4
        Case Else
    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.

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. ...


Word Won't Take 'No' for an Answer

If you choose to exit Word and it asks you if you want to save changes to your template, it can be very confusing ...

Discover More

Using Text As a Page Border

Word allows you to add page borders to a document, but you might find the options in this area too limiting. What if you want ...

Discover More

Selective Summing

If you want to add up the contents of a range of cells based on what is contained in a different range of cells, you need the ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!


Specifying Print Quantity in a Cell

When you print a worksheet, you can specify in the Print dialog box how many copies you want printed. If you want the print ...

Discover More

Protecting Print Settings

Need to have your print settings always be a certain way? Tired of resetting the settings after others use the workbook or ...

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 just ...

Discover More

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:

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}] in your comment text. You’ll be prompted to upload your image when you submit the comment. 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 3 - 0?

2017-01-15 07:21:27

satish babu

sir,i want Printing range based on Cell Contents....
ex:E1=2,print sheet2 A1:J25
E1=3,print sheet3 A1:B20
like that i want 15 sheets print based on cell value..pls help

2016-08-30 19:08:24


I am trying to get a certain range of workesheets to print if a word is placed in a certain cell for example,
If cell C10 in the worksheet titled Input Form says intake then it will print
Worksheets("Agency to Agency Agreement").PrintOut Copies:=Worksheets("PrintInfo").Range("B3")
Worksheets("CW Grievance Guidelines").PrintOut Copies:=Worksheets("PrintInfo").Range("B4")
Worksheets("Medical Treatment").PrintOut Copies:=Worksheets("PrintInfo").Range("B5")
Worksheets("CRMCIA").PrintOut Copies:=Worksheets("PrintInfo").Range("B30")
Worksheets("Client Disciplinary P. & P.").PrintOut Copies:=Worksheets("PrintInfo").Range("B6")
Worksheets("Client Discharge").PrintOut Copies:=Worksheets("PrintInfo").Range("B7")
Worksheets("Emergemcy Information Log").PrintOut Copies:=Worksheets("PrintInfo").Range("B8")
Worksheets("Client Grievance Guidelines").PrintOut Copies:=Worksheets("PrintInfo").Range("B9")
Worksheets("Client Personal Rights").PrintOut Copies:=Worksheets("PrintInfo").Range("B10")

If not then then the same sheets except the Range would change to "C".


2015-11-15 18:20:12



I don't know almost nothing on VBA programming but based on your example, I made the program bellow:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim targCell As Range
Set targCell = Folha(2).Range("G4")
Set printoutauthorization = Folha(1).Range("R5")

If Not Application.Intersect(Target, targCell) Is Nothing Then
If printoutauthorization.Value = SIM &
If targCell.Value <> 0 Then
End If
End If
End Sub

What I need is to allow printing if cell printoutauthoirzation have the value SIM and if cell G4 is diferent than zero.

Waht I'm doing wrong?

Please help.


2014-10-17 06:37:47



Thanks for this. I dont have any knowledge of VB and therefore unable to modify this code to suit my requirement. Are you able to help please?

I have 4 different sheets. The sheets hide/unhide based on "yes"/"No" in a cell.

What i would like is for the user to be able to enter a number against each sheet "X" they have chosen to unhide.

Finally i want to execute a command where the print command prints the unhidden sheets and pick the number of pages depending on the cell vallue of "X".

I know this is possible and you help would be much appreciated.


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

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