View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Yngve Yngve is offline
external usenet poster
 
Posts: 67
Default macro to select cells containing specific text and delete all cells but these

hi



Sub NotDelete()


Dim rng As Range, cell As Range, del As Range
Set rng = Intersect(Range("A:A"), ActiveSheet.UsedRange)
For Each cell In rng

If InStr(cell.Value, "LW") = 0 Then ' delete al rows without "LW"
'If InStr(cell.Value, "LW") < 2 Then ' ' delete al rows with "LW"

If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.Delete '

End Sub

Regards Yngve