I have the folowing code below to show the page Preview
I need the code amended as follows when in page preview mode
1) Hide Cols B:F
2) Autofit the remaining columns
Your assistance is most appreciated
I need the code amended as follows when in page preview mode
1) Hide Cols B:F
2) Autofit the remaining columns
Your assistance is most appreciated
Code:
Sub Print_Preview()
Dim lr As Long
Dim rngCell As Range
With Sheets("Summary")
lr = .Cells(.Rows.Count, "A").End(xlUp).Row
' Hide columns C to E if not already hidden
If Not .Columns("C:E").Hidden Then
.Columns("C:E").Hidden = True
End If
With .PageSetup
.PrintGridlines = True
.PrintArea = "A1:A" & lr & ", F1:AC" & lr
.PrintTitleRows = "$1:$1"
.PrintTitleColumns = "A:B"
.LeftHeader = "&D&T"
.CenterHeader = "Turnover"
.Orientation = xlLandscape
.FitToPagesWide = 1
End With
.UsedRange.SpecialCells(xlCellTypeVisible).EntireColumn.AutoFit
.Activate ' Activate the sheet before the page preview
' AutoFit the columns A to AC, excluding columns C to E
.Columns("A:AC").AutoFit
.Columns("C:E").ColumnWidth = 0 ' Set width to 0 to hide the columns
ActiveWindow.View = xlPageBreakPreview
End With
End Sub