Coding Help

S

Stan

I'm wanting to find rows in a spreadsheet that contains the words "Use Start"
and if not found, delete the rows that do not contain the text. Here's what
I have but it doesn't work. Any help you can provide would be greatly
appreciated.

Sub cleanup2()
Dim rng As Range
Set rng = Range("A:A").Find(What:="Use Start", After:=ActiveCell,
LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If rng Is Nothing Then
Do
Row.Delete

Loop While rng Is Nothing
End If

End Sub
 
D

Don Guillett

Key is to work from the bottom up. Either revise your formula using
findPREVIOUS within FINDNEXT or this.

Sub delallbut()
For i = Cells(Rows.Count, "a").End(xlUp).Row To 2 Step -1
If UCase(Cells(i, "a")) <> "USE START" Then Rows(i).Delete
Next i
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