Manual page break on certain word

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I need to page break on each row containing a specific word in Col. A. I've
tried different code to accomplish this but it didn't work. I'm getting an
"object required" error which doesn't surprise me as I'm not very good at
this. Any and all help would be greatly appreciated; please be specific as
I'm rather a dolt. Thanks!
 
Maybe something like:

Option Explicit
Sub testme()
Dim myRng As Range
Dim FoundCell As Range
Dim FirstAddress As String

With Worksheets("sheet1")
.ResetAllPageBreaks 'remove them all to start
With .Range("a:a") 'what was selected??
Set FoundCell = .Find(What:="whatgoeshere", _
After:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
Lookat:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)

If FoundCell Is Nothing Then
'not found on the sheet
Else
FirstAddress = FoundCell.Address
Do
If FoundCell.Row > 1 Then
.Parent.HPageBreaks.Add Before:=FoundCell
End If
Set FoundCell = .FindNext(FoundCell)
Loop While Not FoundCell Is Nothing _
And FoundCell.Address <> FirstAddress
End If
End With
End With
End Sub
 
Dave,
The code works great! I can't thank you enough and I'm sure I'll be using
it in more than one spreadsheet, so you've really helped me out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top