PDA

View Full Version : Print sheets based on partial sheet name?



Maverick21
07-22-2016, 07:30 AM
Each sheet is named TAG***x and the number of sheets that exists in the worksheet varies each use. How do I create a macro to print only sheets that start with "TAG"?

mdmackillop
07-22-2016, 08:18 AM
For Each sh In Worksheets
If Left(sh.Name, 3) = "TAG" Then sh.Printout
End If

Maverick21
07-22-2016, 08:34 AM
Make it look so simple why don't you...


Edit: Oh and thanks!

mdmackillop
07-22-2016, 08:58 AM
Here's the other way.

Dim arr()
ReDim arr(Worksheets.Count)
For Each sh In Worksheets
If Left(sh.Name, 3) = "TAG" Then
arr(i) = sh.Name
i = i + 1
End If
Next sh
ReDim Preserve arr(i - 1)
Sheets(arr).PrintOut

Use this if you want Header/Footer page numbering to continue throughout the print.