Note: The other languages of the website are Google-translated. Back to English
English English

How to print specific sheet based on cell values in Excel?

Have you ever tried to print some specific sheets based on a cell value? In this article, I will talk about some examples about this issue, if you are interested in this problem, please go on.

Print sheet based on a cell with VBA

Print sheet based on adjacent cell with VBA

Print sheet based on a cell with VBA

Supposing there are two sheets, you want to print Sheet1 or Sheet2 or both sheets based on Cell A1 in the Sheet1. Please do as below:

In this case, enter 1 indicates to print the first sheet, enter 2 to print the second sheet, and 3 to print both sheets.

1. Enter 1, 2, or 3 as you need to A1 in the first sheet, and press Alt + F11 keys to open Microsoft Visual Basic for Applications window. See screenshot:
doc print sheet by cell 1

2. Click Insert > Module, and paste below code in the Module script. See screenshot:

VBA: Print Sheet based on cell value

Sub PrintStuff()
    Dim xRgVal As Variant
    Dim xSheets As Sheets
    Set xSheets = ActiveWorkbook.Worksheets
    xRgVal = xSheets(1).Range("A1").Value
    If (IsNumeric(xRgVal)) And (Len(xRgVal) = 1) Then
        Select Case xRgVal
            Case 1
            Case 2
            Case 3
            Case Else
                MsgBox "Enter1,2 or 3 into A1(1 print Sheet1 2 print Sheet2 3 print Sheet1 and Sheet2 ", , "KuTools For Excel"
                Exit Sub
            End Select
        Exit Sub
    End If
End Sub

doc print sheet by cell 2

3. Press F5 key to directly print the sheet(s).

Print sheet based on adjacent cell with VBA

If you have multiple sheets in a workbook, and you want to print one or several sheets based on cell values from this workbook, you can do as below:

1. Create a new sheet named Control Sheet in the workbook you use, and list all sheet name in column A (include or exclude the control sheet as you need). See screenshot:
doc print sheet by cell 3

2. Type “print” in the adjacent cell next to the sheet name if you want to print it. See screenshot shown.
doc print sheet by cell 4

3. Press Alt + F11 keys to enable the Microsoft Visual Basic for Applications window, and click Insert > Module. See screenshot:
doc print sheet by cell 5

4. Paste below code to the Module, and press F5 key to run the code.

VBA: Print based on adjacent cell

Sub CreateControlSheet()
    Dim i As Integer
    Dim xCSheetRow As Integer
    Dim xSName As String
    Dim xCSheet As Variant
    Dim xRgVal As String
    On Error Resume Next
    xSName = "Control Sheet"
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set xCSheet = ActiveWorkbook.Worksheets(xSName)
    xCSheetRow = xCSheet.Range("B65536").End(xlUp).Row
    For i = 2 To xCSheetRow
        xRgVal = xCSheet.Range("B" & i).Value
        If xRgVal = "Print" Or xRgVal = "print" Then
            If xCSheet.Range("A" & i).Value <> "" Then
                ActiveWorkbook.Worksheets(xCSheet.Range("A" & i).Value).PrintOut
            End If
        End If
    ActiveSheet.Name = "Control Sheet"
    ActiveCell.FormulaR1C1 = "Sheet Name"
    ActiveCell.FormulaR1C1 = "Print?"
    For i = 1 To ActiveWorkbook.Worksheets.Count
        Range("A" & i + 1).Value = ActiveWorkbook.Worksheets(i).Name
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
End Sub

 doc print sheet by cell 6

After running the code, the sheet(s) will be printed right now, and at the same time, a new Control Sheet will replace the old one.

Tip.If you have Kutools for Excel’s Create List of Sheet Names utility, you can quickly create a list of all sheet name in a new sheet with a clickable link.It’s full function without limitation in

Kutools for Excel, with more than 300 handy functions, makes your jobs more easier. 
days, please download and have a free trial now.
doc print sheet by cell 7

The Best Office Productivity Tools

Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%

  • Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
  • Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
  • Merge Cells/Rows/Columns without losing Data; Split Cells Content; Combine Duplicate Rows/Columns... Prevent Duplicate Cells; Compare Ranges...
  • Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
  • Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
  • Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
  • Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
  • Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
  • More than 300 powerful features. Supports Office/Excel 2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features 30-day free trial. 60-day money back guarantee.
kte tab 201905

Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
officetab bottom
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Leave your comments
Posting as Guest
Rate this post:
0   Characters
Suggested Locations