I have the following Code below to Set the Page Layout from Sheet BR1 South to Last Sheet
The code works well, except that I need t autofit the columns as they display ##### in Page Preview Mode
It would be appreciated if someone could amend my code
The code works well, except that I need t autofit the columns as they display ##### in Page Preview Mode
It would be appreciated if someone could amend my code
Code:
Sub SetPageSetupFromBR1SouthToLastSheet()
Dim wb As Workbook
Dim ws As Worksheet
Dim StartProcessing As Boolean
Dim printArea As String
Dim col As Range
' Optimization settings
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
Application.PrintCommunication = False ' Speeds up print-related tasks
' Set the workbook
Set wb = ThisWorkbook
' Initialize variables
StartProcessing = False
printArea = "A1:L40"
' Loop through sheets
For Each ws In wb.Sheets
' Start processing only from "B11 South."
If StartProcessing Or ws.Name = "BR1 South." Then
StartProcessing = True
' Only apply settings if A1 is not blank
If Not IsEmpty(ws.Range("A1").Value) Then
' Page setup adjustments
With ws.PageSetup
.Orientation = xlLandscape ' Landscape orientation
.printArea = printArea ' Set print area
.PrintGridlines = False ' Remove gridlines
.Zoom = False ' Use scaling
.FitToPagesWide = 1 ' Fit to one page wide
.FitToPagesTall = 1 ' Fit to one page tall
End With
' Autofit columns
ws.Columns.AutoFit
' Add buffer to column widths
For Each col In ws.UsedRange.Columns
col.ColumnWidth = col.ColumnWidth + 1 ' Add a small buffer
Next col
End If
End If
Next ws
' Restore application settings
Application.Calculation = xlCalculationAutomatic
Application.PrintCommunication = True
Application.ScreenUpdating = True
Application.EnableEvents = True
Application.DisplayAlerts = True
MsgBox "Page setup and column autofit (with buffer) applied from 'BR1 South.' to the last sheet.", vbInformation
End Sub