+ Reply to Thread
Results 1 to 2 of 2

Thread: Insert Pagebreak Insert pagebreak in next row where value matches the value in A1

  1. #1
    Registered User
    Join Date
    08-03-2010
    Location
    California, US
    MS-Off Ver
    Excel 2007
    Posts
    1

    Lightbulb Insert Pagebreak Insert pagebreak in next row where value matches the value in A1

    I have a book with many sheets. In each sheet the case is the same. I have a value in A1, which will be found in 1 other A cell in unknown row. I want to insert a page break in the matching row. Let's say A1 value is: F342, I want to find the other F342, which happens to be (this time) in A349. Then I want to insert a page break in row 349. I would love to loop through my sheets as well, but not the 2 sheets named "Stops1" and "Stops1 Summary"

    Please help.

  2. #2
    Forum Guru Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007
    Posts
    3,523

    Re: Insert Pagebreak Insert pagebreak in next row where value matches the value in A1

    Copy this code into a standard module. It will loop through the sheets, excluding the ones you named, and look down column-A for another occurence of the value in A1 of each sheet and set a horizontal page break before the row where the value is found.

    Option Explicit
    
    Sub insert_Hpagebreak()
    
        Dim ws As Worksheet, rFound As Range
        
        On Error Resume Next
        
        For Each ws In ThisWorkbook.Worksheets
            If ws.Name <> "Stops1" Or ws.Name <> "Stops1 Summary" Then
                With ws
                    .ResetAllPageBreaks
                    Set rFound = .Columns("A").Find(what:=.Range("A1").Value, after:=.Cells(2, 1), LookIn:=xlValues, _
                        lookat:=xlWhole, searchorder:=xlByRows, searchdirection:=xlNext)
                    
                    If Not rFound Is Nothing Then
                        ws.HPageBreaks.Add before:=rFound
                    End If
                        
                End With
            End If
        Next ws
    
    End Sub
    Palmetto

    Do you know . . . ?

    You can leave feedback and add to the reputation of all who contributed a helpful response to your solution by clicking the star icon located at the left in one of their post in this thread.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0