Hide 2nd pagebreak VBA

bluesteelday

New Member
Joined
Nov 12, 2013
Messages
2
Hi Guys,
I have page breaks in every excel sheet (Page 1,Page 2) set for printing purposes.

What I would like to do is hide the 2nd page in each sheet and keep the 1st page.
I need this to be active for all sheets except sheet named "Other"
This is my code:


For Each ws in application.activeworkbook.worksheets
if ws.name <> ("Other") Then:

-----------------------
Thanks!
 

Some videos you may like

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,882
Assuming your data is such that the second page is below the first, not to the right of the first:

Code:
Option Explicit

Sub HideRowsAfterFirstSheet()

    Dim ws As Worksheet
    Dim lLastRow As Long
    Dim HBreak1 As String
    Dim lHBreak1Row As Long
    
    For Each ws In Application.ActiveWorkbook.Worksheets
        If ws.Name <> ("Other") Then
            With ws
                lLastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
                If .HPageBreaks.Count > 0 Then
                    HBreak1 = .HPageBreaks(1).Location
                    lHBreak1Row = .Range(HBreak1).Row
                    .Range(.Cells(lHBreak1Row, 1), .Cells(lLastRow, 1)).EntireRow.Hidden = True
                End If
            End With
        End If
    Next
    
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,122,464
Messages
5,596,288
Members
414,052
Latest member
Dual Showman

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
Top