Thread: Delete rows
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson[_3_] Jim Thomlinson[_3_] is offline
external usenet poster
 
Posts: 983
Default Delete rows

There is really no advantage to doing an and since you are just doing a find.
You are only looking at matches so just run the code twice. It will do
exactly the dame amount of work. That is the beauty of doing .Find. If you
were traversing through Column 12 looking at each cell then that would be a
very different story. Looping twice in that case would take twice as long.

ans = "Inactive"
With Columns(12)
Do
Set c = .Find(ans, LookIn:=xlValues)
If Not c Is Nothing Then
c.EntireRow.Delete
End If
Loop While Not c Is Nothing
End With

ans = "Closed"
With Columns(12)
Do
Set c = .Find(ans, LookIn:=xlValues)
If Not c Is Nothing Then
c.EntireRow.Delete
End If
Loop While Not c Is Nothing
End With

HTH

"Steph" wrote:

Can this code be modified so that ans = 2 things, "inactive" and "closed"?
The code currently finds the word "inactive" in column 12 and deletes the
row. I would like it to find both "inactive" and "closed", and delete those
rows. Thanks!

ans = "Inactive"
With Columns(12)
Do
Set c = .Find(ans, LookIn:=xlValues)
If Not c Is Nothing Then
c.EntireRow.Delete
End If
Loop While Not c Is Nothing
End With