deleting rows in a worksheet if condition is met

D

destine

hi,

I am trying to come up with a code that will somehow delete an entire row if
it's content in a particular column meets the condition. Say I want to
delete the rows whose Status column says approved.

Anybody can help?
 
P

Pete_UK

You can do it manually by applying Autofilter to the status column and
selecting "approved" from the drop-down. Then highlight all the
visible rows and click on Edit | Delete Row. Then select "All" from
the filter drop-down.

Hope this helps.

Pete
 
M

Mike H

Hi,

Right click your sheet tab, view code and paste this in. Change the letter
in the line
mycolumn = "C" 'Change to suit
to the column where your string is.

Sub copyit()
mycolumn = "C" 'Change to suit
Dim MyRange, MyRange1 As Range
lastrow = Cells(Rows.Count, mycolumn).End(xlUp).Row
Set MyRange = Range(mycolumn & "1:" & mycolumn & lastrow)
For Each c In MyRange
If UCase(c.Value) = "APPROVED" Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub


Mike
 
K

kevin

I like this code and it works for some of my applications as well. I need
something similar that will delete the row if the column contains "FM" in a
text string (not equal to). I also need syntax that would delete the row if
it does NOT contain "FM".

Can that be done with your code here?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top