Macro is printing hidden sheets that I don't need

Busscheduler

New Member
Joined
Nov 23, 2020
Messages
41
Office Version
  1. 2016
Platform
  1. Windows
I know that this has been covered in other threads, and I have searched some of those but have not found a code that will work.

I have a sheet that contains all seven days of the week, and depending on which times the theme parks close, each day uses different pages that I want to print. For example, Monday is made up of pages 1-4 and some days I would need to print 1 and 2, and other days 1 and 3 or 1 and 4, etc. The rows that I don't need printed are hidden before printing. I recorded a macro using "Print selection" and included the full range of the 4 pages for Monday:

Sub PrintMondaySelection()
'
' PrintMonday Macro
'

'
Range("L1").Select ' Copies which route should be highlighted
Selection.Copy
Range("K1").Select ' Pastes the route in cell K1. This activates the conditional formatting.
ActiveSheet.Paste
Range("A1:J133").Select ' Range of cells for pages 1-4
Application.CutCopyMode = False
Selection.PrintOut Copies:=1, Collate:=True
Range("A1:D1").Select

End Sub

Using this macro, I get the pages I want printed but it also includes a blank page for each hidden page. I'm not sure how to get it to stop that.

Thanks.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Sub PrintMondaySelection()
'
' PrintMonday Macro
'

'
Range("L1").Select
Selection.Copy
Range("K1").Select
ActiveSheet.Paste
Range("A1:J133").Select
Application.CutCopyMode = False
Selection.Printout Copies:=1, Collate:=True
Range("A1:D1").Select

End Sub
 
Upvote 0
Perhaps you are looking for something like this ...

VBA Code:
Sub Print_Example()
    With ActiveSheet
        .Range("L1").Copy Destination:=.Range("K1")
        .PageSetup.PrintArea = "$A$1:$J$133"
        .Range("A1:J133").PrintOut Copies:=1, Collate:=True
        .Range("A1:D1").Select
    End With
End Sub
 
Upvote 0
GWteB, I ran the code that you suggested but it still prints a blank page along with the pages I want.
 
Upvote 0
How does your worksheet look like?
 
Upvote 0
Sure, use a sharing site like Dropbox or Google drive and be sure to mark your file as shared. Post the link in this thread.
 
Upvote 0
I cannot download your file from my present location, but I have some questions for you.

Do you really have multiple sheets (tabs) in your Excel file?
Or is it really a matter of one single sheet with many rows that are printing on to multiple sheets?

Is it printing hidden rows?
Or do you have blank rows at the bottom that are being printed (i.e. you do not have data all the way down to row 133)?

Also note that if printing from columns A to J exceeds the width of a single page, you will get this to cause to print twice as many sheets as you want.
If you change Page Setup to "Fit to 1 page wide by 9999 tall", that should prevent that from happening.
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,048
Members
448,543
Latest member
MartinLarkin

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