#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 60
Default If multiple criteria

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!
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 793
Default If multiple criteria

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?

"Matt" wrote:

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!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default If multiple criteria

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


Uzytkownik "Matt" napisal w wiadomosci
...
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!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Count multiple cells against multiple criteria in an Excel spreads EricB Excel Worksheet Functions 7 June 3rd 08 09:09 PM
match multiple criteria ina range from multiple criteria multiplet RG Excel Worksheet Functions 8 September 28th 07 04:21 AM
Index & Match functions - multiple criteria and multiple results [email protected] Excel Worksheet Functions 4 May 2nd 07 03:13 AM
Counting Cells with multiple criteria.One criteria supporting wild Azhar Saleem Excel Worksheet Functions 1 January 12th 05 10:54 AM
Counting Cells with multiple criteria.One criteria supporting wild Azhar Arain Excel Worksheet Functions 1 January 12th 05 08:33 AM


All times are GMT +1. The time now is 02:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"