View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Jackson Jim Jackson is offline
external usenet poster
 
Posts: 324
Default Marco to delete all rows except those containing 'MZ' in string

Sub Delete_Row()
Range("A1").Activate
Do
If Instr(Activecell) = "MZ" then
Activecell.Offset(1,0).Activate
Else
Activecell.EntireRow.Delete Shift:=XLUp
End if
Loop until Activecell = "
End Sub
--
Best wishes,

Jim


" wrote:

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