Need Macro

  • Thread starter Thread starter DollarBill
  • Start date Start date
D

DollarBill

I would like to delete rows based on if a cell has a particular value. E.g.
Column M has a string value, "1 2 3 A B C". I would like to delete all rows
that DO NOT contain value "C".

Thanks,
Bill
 
Select column M
Data|filter|autofilter
use the dropdown arrow and select Custom
and
Does not contain
C

Delete the visible rows

and data|filter|autofilter to remove that filter.
 
And if you really needed a macro, record one when you do it manually. You'll
have code that may need a bit of tweaking, though.
 
Sub deleteifG()
For i = 2 To Cells(Rows.Count, "M").End(xlUp).row
If InStr(Cells(i, "m"), "c") < 1 Then Rows(i).Delete
Next i
End Sub
 
Dave Peterson said:
Select column M
Data|filter|autofilter
use the dropdown arrow and select Custom
and
Does not contain
C

Delete the visible rows

and data|filter|autofilter to remove that filter.

Okay, that works. I'm just having one problem, if one of the values is AC,
it's returning that row as well. I tried quotation marks but that didn't
work.

Thanks.
 
Are you sure that you used "does not contain: C"?

And are you sure that your filtered range included that row?

I've never seen excel mess up like that.
 
It seems to be working now. I'm not sure what I did or didn't do.
Regardless, it's working. Thanks.
 
Back
Top