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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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