If multiple criteria

M

Matt

I'd like to create a code that would go through a list of values
(starting in A1 and going down), and for each value, if it equals a
value specified in a list (say numbers 187 or 199), then it deletes
the entire row. I realize the following script is probably more than
it needs to be, can someone help?

Sub Delete_Rows()

For Each Row In Rows("1:65536")
For Each i In MyArray(187, 199)
If Cells(Row, 1).Value = i Then
Rows(Row).Delete
Next i
Next Row

End Sub

Thanks!
 
S

Sheeloo

While deleting you should start at the bottom and move up...
Try
Dim myarray(2) As Long
myarray(0) = 187
myarray(1) = 199

With ActiveSheet
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
'lastCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With
For i = lastrow To 1 Step -1
For Each j In myarray()
If Cells(i, 1).Value = j Then
Rows(i).Delete
End If
Next j
Next i

End Sub

Could you run your code?
 
J

Jarek Kujawa

Sub Delete_Rows()
Dim cell as Range

For Each cell In Range("A1:A65536").Cells
If Cells(cell.Row, 1).Value = 187 Or Cells(cell.Row, 1).Value =
199 Then
Rows(cell.Row).EntireRow.Delete
End if
Next cell

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