Thread
:
Marco to delete all rows except those containing 'MZ' in string
View Single Post
#
5
Posted to microsoft.public.excel.programming
Don Guillett
external usenet poster
Posts: 10,124
Marco to delete all rows except those containing 'MZ' in string
try this using col A
Sub Delete_Row()
For i = Cells(Rows.Count, "a"). _
End(xlUp).Row To 2 Step -1
If InStr(UCase(Cells(i, "a")), "MZ") 0 _
Then Rows(i).Delete
Next i
End Sub
--
Don Guillett
SalesAid Software
wrote in message
oups.com...
I have a macro which does the does the opposite of what I want. It
deletes all the rows that contains MZ in the first column and leaves
everything behing. I just want to keep the rows that contain MZ in the
first column and delete all the others rows. Any help will be greatly
appreciated. Here is what I have;
Sub Delete_Row()
Dim myWord As String
myWord = "MZ"
With ActiveSheet
On Error Resume Next
Do
.Cells.Find(What:="MZ", After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, Lookat:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=True).EntireRow.Delete
If Err.Number < 0 Then Exit Do
Loop
On Error GoTo 0
End With
End Sub
Reply With Quote
Don Guillett
View Public Profile
Find all posts by Don Guillett