code to remove rows containing a character string
Hi,
Right click your sheet tab, view code and paste this in and run it and all
rows with FM in the string in Col C will be deleted.
If you then to go on the delete all rows that don't contain FM all yoiur
data will be gone so I think you need to re-visit the second part of your
question
Sub delete_Me()
Dim copyrange As Range
Lastrow = Cells(Cells.Rows.Count, "C").End(xlUp).Row
Set MyRange = Range("C1:C" & Lastrow)
For Each c In MyRange
If InStr(c, "FM") Then 'Red change to suit
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub
Mike
"kevin" wrote:
I want to create a macro to remove all the rows of a table in which the cell
in column C contain "FM" within the text string. For some reason, when I set
up a macro to do a filter of "contains FM" then try to delete just those
rows, the macro deletes all rows.
After that ... I need to do the opposite. Need to delete all rows that does
NOT contain "FM".
Any help is appreciated.
|