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.
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.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks