adjustment to print code needed

palaeontology

Active Member
Joined
May 12, 2017
Messages
444
Office Version
  1. 2016
Platform
  1. Windows
Hi, I'm currently using the following code to print pages 1 and 2 of any worksheet named with a 4-digit number ...

Code:
For Each ws In ThisWorkbook.Worksheets
    If ws.Name Like "#####" Then
        ws.Range("P22:U22").Font.Color = vbWhite
        ws.Range("P22:U22").Interior.Color = vbWhite
        ws.PageSetup.Orientation = xlLandscape
        ws.PrintOut From:=1, To:=1
        ws.PageSetup.Orientation = xlLandscape
        ws.PrintOut From:=2, To:=2
    End If
Next ws

so, currently, if there are 6 worksheets named with a 4-digit code, each worksheet will have their page 1 and 2 printed.

However, my needs have now changed. Is there a way to have ....

* page 1 printed (in landscape) for each worksheet named with a 4-digit code
* page 1 printed (in landscape) for the worksheet named .... Explanations

PLEASE READ THIS NEXT BIT !

I need the 'Explanations' worksheet (page 1) only printed just the once, regardless of how many 4-digit worksheets are being printed.

That is, if there are seven (7) worksheets with a 4-digit name each having their page 1 printed, then there would be a total of eight (8) pages being printed, as the 'Explanations page only needs to be printed once.

I hope this makes sense.

Kind regards,

Chris
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Something like this you mean?

Code:
For Each ws In ThisWorkbook.Worksheets    If ws.Name Like "#####" Then
        ws.Range("P22:U22").Font.Color = vbWhite
        ws.Range("P22:U22").Interior.Color = vbWhite
        ws.PageSetup.Orientation = xlLandscape
        ws.PrintOut From:=1, To:=1
    ElseIf ws.Name = "Explanations" Then
        ws.PageSetup.Orientation = xlLandscape
        ws.PrintOut From:=1, To:=1
    End If
Next ws
 
Upvote 0

Forum statistics

Threads
1,214,789
Messages
6,121,605
Members
449,038
Latest member
Arbind kumar

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