search for a string

S

santana

How can I search for a string (“Draft Documentsâ€) in sheet1 and then delete
all the rows above the row containing the string and then delete the last two
rows in sheet1? Thank you
 
O

ozgrid.com

Try;

Sub DoIt()
Dim rRange As Range

On Error Resume Next
Set rRange = Range(Cells(1, 1). _
Cells.Find("Draft Documents", _
Cells(1, 1), xlFormulas, _
xlWhole, xlByRows, xlNext, False))
On Error GoTo 0

If Not rRange Is Nothing Then
rRange.EntireRow.Delete
Else
MsgBox "'Draft Documents' Not found"
End If

Set rRange = Cells.Find("*", _
Cells(1, 1), xlFormulas, _
xlPart, xlByRows, xlPrevious, False)

rRange.Offset(-2, 0).Range("A1:A2").EntireRow.Delete
End Sub
 

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

Top