Macro to print sheets based on list

manekankit

Board Regular
Joined
Feb 1, 2019
Messages
72
Office Version
  1. 365
Platform
  1. Windows
Need help with macro to perform following task.

1. I have a file (Original file) with 5 sheets (Index, Report1, Report2, Report3, and Report4)
3. Colum C in Index sheet contains list of sheets which are to be sent for printing to the default printer (e.g. it contains Report1 and Report2 in cells C1 and C2 respectively). This list can increase or decrease.

Required:
Request you to help with macro code that will trigger print for sheets listed in column C of the Index sheet.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi manekankit,

Try this:

VBA Code:
Option Explicit
Sub Macro1()

    Dim wsSrc As Worksheet
    Dim wsPrint As Worksheet
    Dim rngCell As Range
    
    Application.ScreenUpdating = False
    
    Set wsSrc = ThisWorkbook.Sheets("Index")
    
    For Each rngCell In wsSrc.Range("C1:C" & wsSrc.Range("C" & Rows.Count).End(xlUp).Row)
        If Len(rngCell.Value) > 0 Then
            On Error Resume Next
                Set wsPrint = ThisWorkbook.Sheets(CStr(rngCell.Value))
                If Err.Number = 0 Then
                    wsPrint.PrintOut Copies:=1
                End If
            On Error GoTo 0
        End If
    Next rngCell
    
    Application.ScreenUpdating = True

End Sub

Regards,

Robert
 
Upvote 0
Solution

Forum statistics

Threads
1,223,948
Messages
6,175,571
Members
452,652
Latest member
eduedu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top