Richie(UK)
MrExcel MVP
- Joined
- May 17, 2002
- Messages
- 3,329
Hi all,
I have some VBA code (see below) to set-up custom headers and footers based upon worksheet values. The headers and footers are to be applied to each of the (4) worksheets in the workbook.
The code works but is VERY slow. Anybody got any tips on speeding it up? (And I don't mean the 'buy a faster computer' type of tip :wink: )
I have some VBA code (see below) to set-up custom headers and footers based upon worksheet values. The headers and footers are to be applied to each of the (4) worksheets in the workbook.
The code works but is VERY slow. Anybody got any tips on speeding it up? (And I don't mean the 'buy a faster computer' type of tip :wink: )
Code:
Sub CustomHeaderFooter()
Dim ws As Worksheet
Dim strLH As String, strCH As String, strRH As String
Dim strLF As String, strCF As String, strRF As String
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
With Sheet1
strLH = .Range("C43").Value
strCH = .Range("C44").Value
strRH = .Range("C45").Value
strLF = .Range("C46").Value
strCF = .Range("C47").Value
strRF = .Range("C48").Value
End With
'get values from Sheet1 (User Input)
For Each ws In ThisWorkbook.Worksheets
With ws.PageSetup
.LeftHeader = strLH
.CenterHeader = strCH
.RightHeader = strRH
.LeftFooter = strLF
.CenterFooter = strCF
.RightFooter = strRF
End With
Next
'pass values to PageSetup
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub