Macro to show Page Preview

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,595
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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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