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!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

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