lynnsong986
Board Regular
- Joined
- May 24, 2014
- Messages
- 146
Hello,
I have the below codes that run really slowly, it loops each sheet and find the dynamic range then set the printing area on each. it works but takes a long time (the workbook has about 130 sheets and it takes almost 30 minutes to loop through!)
Can someone please help me revise it to make it run faster?
Also how can I post codes where it belongs...
Sub SetPrintAreaOnMultipleSheetsForReport()
Dim sh As Worksheet
For Each sh In ActiveWindow.SelectedSheets
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.PrintCommunication = False
sh.Activate
myrange = ActiveSheet.Cells(Rows.Count, 9).End(xlUp).Address
ActiveSheet.PageSetup.PrintArea = "$A$1:" & myrange
ActiveSheet.PageSetup.Orientation = xlPortrait
With ActiveSheet.PageSetup
.FitToPagesWide = 1
.FitToPagesTall = 20
End With
Next sh
Application.PrintCommunication = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
thanks,
Lynn
I have the below codes that run really slowly, it loops each sheet and find the dynamic range then set the printing area on each. it works but takes a long time (the workbook has about 130 sheets and it takes almost 30 minutes to loop through!)
Can someone please help me revise it to make it run faster?
Also how can I post codes where it belongs...
Sub SetPrintAreaOnMultipleSheetsForReport()
Dim sh As Worksheet
For Each sh In ActiveWindow.SelectedSheets
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.PrintCommunication = False
sh.Activate
myrange = ActiveSheet.Cells(Rows.Count, 9).End(xlUp).Address
ActiveSheet.PageSetup.PrintArea = "$A$1:" & myrange
ActiveSheet.PageSetup.Orientation = xlPortrait
With ActiveSheet.PageSetup
.FitToPagesWide = 1
.FitToPagesTall = 20
End With
Next sh
Application.PrintCommunication = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
thanks,
Lynn