Macro to delete row dependant on value of cell

Jburgy

New Member
Joined
Aug 15, 2018
Messages
9
Hello!

How would I go about setting up a macro to delete certain rows based on a value in cell I for example

So like: IF Column I = "Cancelled" THEN DELETE Row (Then go on to next row until every row is checked)


I'm new to macros, trying to learn but i'm struggling a bit, help is appreciated! :)
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try this:
Code:
Sub Filter_Me_Please()
'Modified  8/16/2018  7:24:54 AM  EDT
Dim Lastrow As Long
Dim c As Long
Dim s As Variant
c = "9" 'Column Number Modify this to your need
s = "Cancelled" 'Saerch Value Modify to your need
Lastrow = Cells(Rows.Count, c).End(xlUp).Row
With ActiveSheet.Cells(1, c).Resize(Lastrow)
    .AutoFilter 1, s
    counter = .Columns(c).SpecialCells(xlCellTypeVisible).Count
    If counter > 1 Then
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).EntireRow.Delete
    Else
        MsgBox "No values found"
    End If
    .AutoFilter
End With
End Sub
 
Upvote 0
Works perfectly thank you!!

Nicely laid out and nice descriptions, I think i could do this again for different purposes :)
 
Upvote 0
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.

Yes I laid it out where maybe it would be easy to modify to your needs in another project.
 
Upvote 0

Forum statistics

Threads
1,215,217
Messages
6,123,675
Members
449,116
Latest member
HypnoFant

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top