Loading
Excel.Tips.Net ExcelTips (Menu Interface)

Printing Based on Cell Contents

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.

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.

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.

Related Tips:

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!

 

Leave your own comment:

*Name:
Email:
  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*Text:
*What is 5+3 (To prevent automated submissions and spam.)
 
 
           Commenting Terms

Comments for this tip:

Ken    30 Aug 2016, 19:08
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".

Thanks
Mario    15 Nov 2015, 18:20
Hello,

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
            Folha(2).PrintOut
        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.

Thanks
Mário
Navin    17 Oct 2014, 06:37
Hi

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.

Thanks
Navin
 
 

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us

 

Advertise with Us

Our Privacy Policy

Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives

 

Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.