Any suggestions please as to how this code can be sped up or otherwise improved? Showpages creates around 110 sheets that need tweaking (insert some extra rows at the top, pagesetup for print settings, adjust column widths, set freezepanes).
Blue Bits: I guess I could somehow group all the sheets that meet that case and then make the change once.
Red bits: Is there a way that avoids the need to activate and select when freezing panes?
Black bits: Really this is what takes the time and would best benefit from your improvement ideas.
Gavin
Blue Bits: I guess I could somehow group all the sheets that meet that case and then make the change once.
Red bits: Is there a way that avoids the need to activate and select when freezing panes?
Black bits: Really this is what takes the time and would best benefit from your improvement ideas.
Code:
Sub ShowPages()
Dim sh As Worksheet
Dim c As Range
Dim strLF As String, strRF As String 'for footers
strLF = "&""Arial,Italic""&F &A on &D at &T" 'left
strRF = "Page &P of &N" 'right
'Application.Calculation = xlCalculationManual
'Application.ScreenUpdating = False
ActiveSheet.PivotTables("PivotTableMaster").ShowPages PageField:= _
"Budget holder"
For Each sh In Sheets
Select Case sh.Name
Case "Budget Holder Detail", "Portfolio Detail"
'Next sh
Case Else
[blue]sh.Rows("1:3").Insert Shift:=xlDown
Worksheets("Budget Holder Detail").Range("3:4").Copy Destination:=sh.Range("A1")[/blue]
With sh.PageSetup
.PrintTitleRows = "$7:$7"
.LeftFooter = strLF
.RightFooter = strRF
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(1)
.BottomMargin = Application.InchesToPoints(0.6)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.3)
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
For Each c In Range("MyColWidth")
sh.Columns(c.Column).ColumnWidth = c.Value
Next c
End With
[red]sh.Activate
sh.Range("I8").Select
ActiveWindow.FreezePanes = True[/red]
End Select
Next sh
'Application.Calculation = xlCalculationAutomatic
'Application.ScreenUpdating = True
End Sub
Gavin