Prevost
Board Regular
- Joined
- Jan 23, 2014
- Messages
- 198
Hi There. I have this code below which is deleting rows that contain a certain value in the corresponding C column. (I am cleaning up bills of materials that have these redundant lines in them). I have written code like this before to delete lines and it works, but it seems to miss some lines and I have to run it several times to ensure all the rows are deleted. Is there something in the code that is causing this that I am missing (which I think is more likely the case) or has anyone else come across this? Thanks!
Code:
Sub RemoveLines()
Dim MyRange As Range, Cell As Range
Dim Search(1 To 10) As String
Dim i As Integer
Set MyRange = Range("C2:C91953")
Search(1) = "SPARE LINE"
Search(2) = "RAWLBS1"
Search(3) = "RAWLBS2"
Search(4) = "RAWLBS3"
Search(5) = "RAWLBS4"
Search(6) = "RAWFT"
Search(7) = "MISC"
For Each Cell In MyRange
For i = 1 To 7
If Cell = Search(i) Then
Cell.EntireRow.Delete
Exit For
End If
Next i
Next Cell
End Sub