Macro is printing hidden sheets that I don't need

Busscheduler

New Member
Joined
Nov 23, 2020
Messages
26
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.
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Busscheduler

New Member
Joined
Nov 23, 2020
Messages
26
Office Version
  1. 2016
Platform
  1. Windows
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
 

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,295
Office Version
  1. 2013
Platform
  1. Windows
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
 

Busscheduler

New Member
Joined
Nov 23, 2020
Messages
26
Office Version
  1. 2016
Platform
  1. Windows
GWteB, I ran the code that you suggested but it still prints a blank page along with the pages I want.
 

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,295
Office Version
  1. 2013
Platform
  1. Windows

ADVERTISEMENT

How does your worksheet look like?
 

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,295
Office Version
  1. 2013
Platform
  1. Windows

ADVERTISEMENT

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.
 

Busscheduler

New Member
Joined
Nov 23, 2020
Messages
26
Office Version
  1. 2016
Platform
  1. Windows
I hope this works. Here is the link:


The sheet looks very rudimentary.
 

Busscheduler

New Member
Joined
Nov 23, 2020
Messages
26
Office Version
  1. 2016
Platform
  1. Windows
GWteB,
This may be a better file. I uploaded the file instead of copying and pasting.

 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,685
Office Version
  1. 365
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,127,795
Messages
5,626,926
Members
416,209
Latest member
tan21

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
Top