MARK858
MrExcel MVP
- Joined
- Nov 12, 2010
- Messages
- 16,816
- Office Version
- 365
- Platform
- Windows
- Mobile
Hi there, I have found quite a lot of code for inserting page breaks before cells or specific values (like the code below for example, provided by Domenic in a previous thread).
I want to do something very similar but my problem is the only unique keyword I can find in the right position needs to be above the page breaks (i.e. after the keyword).
All the other criteria are the same i.e. the word is in a single column (say "A") and it is a single word (might as well stick to "A" as in Dominic's code).
Is this possible?
I want to do something very similar but my problem is the only unique keyword I can find in the right position needs to be above the page breaks (i.e. after the keyword).
All the other criteria are the same i.e. the word is in a single column (say "A") and it is a single word (might as well stick to "A" as in Dominic's code).
Is this possible?
Code:
Option Explicit
Sub test()
Dim FoundCell As Range
Dim FirstAddress As String
Dim PrevAddress As String
Dim CurrAddress As String
Dim SearchTerm As String
SearchTerm = "A"
With Columns("A")
Set FoundCell = .Find(SearchTerm, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If Not FoundCell Is Nothing Then
FoundCell.Name = "FirstAddress"
Do
PrevAddress = FoundCell.Address
FoundCell.Resize(3).EntireRow.Insert
ActiveSheet.HPageBreaks.Add before:=Range(PrevAddress)
Set FoundCell = .FindNext(FoundCell)
Loop While FoundCell.Address <> Range("FirstAddress").Address
Else
MsgBox "No search term found...", vbExclamation
End If
End With
End Sub