VBA: The Efficiency of a Piece of Code

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
21,577
Office Version
  1. 365
Platform
  1. Windows
According to a client of mine, the following code takes about 20 seconds to run on his computer. However, it only takes about 1.6 seconds to run on my Windows based computer, and about 3 seconds on my old Mac computer. Even with what he says is a slow computer, I don't see why it would take so long. Here's the code...

Code:
Sub UpdateHeader()

    Dim i As Long
     
    ActiveSheet.PageSetup.CenterHeader = Range("q10").Value
    
    With Worksheets(1).PageSetup
         
        For i = 2 To 6
            Worksheets(i).PageSetup.LeftHeader = .LeftHeader
            Worksheets(i).PageSetup.CenterHeader = .CenterHeader
            Worksheets(i).PageSetup.RightHeader = .RightHeader
            Worksheets(i).PageSetup.LeftFooter = .LeftFooter
            Worksheets(i).PageSetup.CenterFooter = .CenterFooter
            Worksheets(i).PageSetup.RightFooter = .RightFooter
        Next i
        
    End With


End Sub

Does any one have any insight, comments, etc.?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
This may be a printer driver issue. My understanding is that any code that changes printing properties interacts with the printer driver.
 
Upvote 0
P.S. In Excel 2010 you can use

Code:
Application.PrintCommunication = False
 
Upvote 0
VoG, shg, Firefly2012

Thank you very much for your help. I wasn't aware of this issue. So it's definitely good to know. I'll post back with the results.

Thanks again!
 
Upvote 0
For compatibility reasons, the XL4 macro was used. Apparently, it was "noticeably faster". :)

Thanks again for everyone's help!

Cheers!
 
Upvote 0

Forum statistics

Threads
1,214,938
Messages
6,122,346
Members
449,080
Latest member
Armadillos

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