Find and delete rows

J

JRSmith

Hi and TIA. What I'm trying to accomplish is to run code that checks column
A starting at A1. Run down until it finds the word "DeleteMe" and from that
row until the end of the document delete all rows. Is that possible?
Thanks for any advice and your time.
 
R

Rick Rothstein

Give this macro a try...

Sub ProcessDeleteMe()
Dim DM As Range
With Worksheets("Sheet1")
On Error GoTo Done
Set DM = .Columns("A").Find(What:="DeleteMe", MatchCase:=False)
Application.Intersect(.UsedRange, Range(DM, .Cells( _
.Rows.Count, "A"))).EntireRow.Delete
End With
Done:
End Sub
 
J

JRSmith

Rick, Thanks for the reply. Works like a charm. Exactly what I was
looking for. At first it didn't work because the cell that held the
deleteme string was a merged cell. Once I unmerged good to go. Thanks
again for your time.


Rick Rothstein said:
Give this macro a try...

Sub ProcessDeleteMe()
Dim DM As Range
With Worksheets("Sheet1")
On Error GoTo Done
Set DM = .Columns("A").Find(What:="DeleteMe", MatchCase:=False)
Application.Intersect(.UsedRange, Range(DM, .Cells( _
.Rows.Count, "A"))).EntireRow.Delete
End With
Done:
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