Printing Worksheets based on name only

WindsorKnot

Board Regular
Joined
Jan 4, 2009
Messages
160
Hi everyone,

I'm trying to figure this out. I need to print a workbook out (about 60 sheets 10 to 15 which shouldn't be printed out) based on whether the sheet contains the name _exhibit. I have a hunch that the workbook should contain an If statement and an array but I'm not sure how to code it properly.



This is what I have so far. To make things simpler, I only copied the first 6 sheets into the formula.


Code:
Sub Print_Exhibit()



Dim Shts

Shts = Array("Sheet1_Exhibit", "Sheet2_Exhibit", "Sheet3", "Sheet4_Exhibit", "Sheet5", "Sheet6_Exhibit")


Dim Shts_E
Shts_E = Filter(Shts, "_Exhibit", True, vbTextCompare)

Dim WS As worksheet


If Wks = "_Exhibit" then Wks.printout

Next wks


End Sub
Any input would be great!:)
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this one

Code:
Sub Print_Exhibit()

Dim Shts As Worksheet
For Each Shts In ActiveWorkbook.Worksheets
    If Shts.Name Like "*_Exhibit*" Then
        wks.PrintOut
    End If
Next Shts

End Sub
 
Last edited:
Upvote 0
Hi,
Try this...
Code:
Sub PrintSpecificSheets()
Dim nSheets As Integer
nSheets = ActiveWorkbook.Sheets.Count
For lSheets = 1 To nSheets
ActiveWorkbook.Sheets(lSheets).Activate
If Right(ActiveSheet.Name, 8) = "_Exhibit" Then ActiveSheet.PrintOut Copies:=1, Collate:=True
Next lSheets

End Sub

This will just loop through all the sheets, test if the name ends in "_Exhibit" (and print if true)

The down side of this method is that it sends the printjob one sheet at a time.
 
Upvote 0
Thanks for the input!

I made the following Modification to Kieran's Code

I decide I was too lazy to always type in _Exhibit for new every worksheet that needed to be created.

Code:
Sub Print_Exhibit()
Dim Shts As Worksheet
For Each Shts In ActiveWorkbook.Worksheets
    If Shts.Tab.ColorIndex = 11 Then
        Shts.PrintOut
    End If
Next Shts
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,733
Members
448,987
Latest member
marion_davis

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