Macro to show Page Preview

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,603
Office Version
  1. 2021
Platform
  1. Windows
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

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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top