How to Print Specific Worksheet from Multiple Worksheets in Workbook Using VBA

Home More Excel (VBA) Training Videos

An interesting and practical question on using Excel VBA to print a specific worksheet from multiple worksheets in a workbook:
'How can I create a macro that can print a specific sheet; my book has 35 sheets; I need something like a window to come up asking what sheet I want to print. Thanks'

We first create a command button so that user can start working with a single click. Then, Because the user wants to enter a sheet number from a pop-up window, we create an inputbox in our VBA or macro code. The value that the user enters in the inputbox is assigned to a variable called myNum. Next we use the worksheets object and assign the index number to it using the value assigned to myNum. Finally we use the 'printout' function to print the worksheet.
The macro or VBA code that can be used with numbered worksheets  is given below for your ready reference:
Private Sub CommandButton1_Click()
Dim myNum As Integer
myNum = Application.InputBox("Enter a sheet number")
Worksheets(myNum).PrintOut
End Sub

For named sheets we can use the following Excel VBA code:
Private Sub CommandButton1_Click()
Dim sheetname As String
sheetname = Application.InputBox("Enter a sheet name")
Sheets(sheetname).PrintOut
End Sub
Watch the Excel training video to see how this interesting VBA solution for printing a specific numbered or named worksheet from multiple worksheets in an Excel workbook is implemented:




Watch the video on our youtube channel
Home More Excel (VBA) Training Videos