Domenic was very kind enough to help with a problem posted here but I would like to expand this code slightly.
What I would like to do with this code is after the 30 rows have been inserted and a page break added, delete the row which has the search term "Test" and the next 2 rows.
This gets rid of the rows that i don't need.
Can anyone please help?
What I would like to do with this code is after the 30 rows have been inserted and a page break added, delete the row which has the search term "Test" and the next 2 rows.
This gets rid of the rows that i don't need.
Can anyone please help?
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 = "Test"
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(30).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