Speeding up a VBA macro for printing headers

robwood83

New Member
Joined
Aug 3, 2010
Messages
5
Hello All,

I have a Macro I am using to apply a custom header to certain sheets in a workbook, only about half the sheets. This is what I am using.
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Worksheets("Sheet1").PageSetup.LeftHeader = "& PETAP# " & Sheets("Turn-In").Range("G28").Value
    Worksheets("Sheet1").PageSetup.RightHeader = Sheets("Turn-In").Range("V28").Value
    Worksheets("Sheet2").PageSetup.LeftHeader = "& PETAP# " & Sheets("Turn-In").Range("G28").Value
    Worksheets("Sheet2").PageSetup.RightHeader = Sheets("Turn-In").Range("V28").Value
    Worksheets("Sheet3").PageSetup.LeftHeader = "& PETAP# " & Sheets("Turn-In").Range("G28").Value
    Worksheets("Sheet3").PageSetup.RightHeader = Sheets("Turn-In").Range("V28").Value
    Worksheets("Sheet4").PageSetup.LeftHeader = "& PETAP# " & Sheets("Turn-In").Range("G28").Value
    Worksheets("Sheet4").PageSetup.RightHeader = Sheets("Turn-In").Range("V28").Value
    Worksheets("Sheet7").PageSetup.LeftHeader = "& PETAP# " & Sheets("Turn-In").Range("G28").Value
    Worksheets("Sheet7").PageSetup.RightHeader = Sheets("Turn-In").Range("V28").Value
    Worksheets("Sheet10").PageSetup.LeftHeader = "& PETAP# " & Sheets("Turn-In").Range("G28").Value
    Worksheets("Sheet10").PageSetup.RightHeader = Sheets("Turn-In").Range("V28").Value
    Worksheets("Sheet12").PageSetup.LeftHeader = "& PETAP# " & Sheets("Turn-In").Range("G28").Value
    Worksheets("Sheet12").PageSetup.RightHeader = Sheets("Turn-In").Range("V28").Value
    Worksheets("Sheet15").PageSetup.LeftHeader = "& PETAP# " & Sheets("Turn-In").Range("G28").Value
    Worksheets("Sheet15").PageSetup.RightHeader = Sheets("Turn-In").Range("V28").Value
    Worksheets("Sheet17").PageSetup.LeftHeader = "& PETAP# " & Sheets("Turn-In").Range("G28").Value
    Worksheets("Sheet17").PageSetup.RightHeader = Sheets("Turn-In").Range("V28").Value
   
End Sub

This is working great but seem to really slow Excel down, is there any other options to accomplish this same thing but without the memory drag?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I'm not sure it'll speed it up because thes page setup things can take a while sometimes but:
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Sheets(Array("Sheet1", "Sheet2", "Sheet3", "Sheet4", "Sheet7", "Sheet10", "Sheet12", "Sheet15", "Sheet17")).Select
Sheets("Sheet1").Activate
With ActiveSheet.PageSetup
  .LeftHeader = "& PETAP# " & Sheets("Turn-In").Range("G28").Value
  .RightHeader = Sheets("Turn-In").Range("V28").Value
End With
End Sub
I don't think you can avoid selecting for these purposes.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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