VBA Delete row if column contains certain text but ignore if a different text is in a different column

tropics123

Board Regular
Joined
May 11, 2016
Messages
85
Hi, looking for some help to take this macro a step further. An illustration below but this is not exact because my sheet will vary with different number of rows daily.

What I'm trying to do: If column E is "0" then delete entire row but if column B has "RK003" then do not delete that row, even if column E has the value "0". My macro can only do the first half of what needs to be done but the second half (in orange font), I don't know how to do. I appreciate your help!

With ActiveSheet
.AutoFilterMode = False
With Range("E1", Range("E" & Rows.Count).End(xlUp))
.AutoFilter 1, "0"
On Error Resume Next
.Offset(1).SpecialCells(12).EntireRow.Delete
End With
.AutoFilterMode = False
End With


End Sub

column Acolumn Bcolumn Ccolumn DColumn E
RK0010
RK0030
RK005687
RK0080
RK0030
RK003100
RK00928
RK0020
RK007155,000

<tbody>
</tbody>
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try this (assuming row 1 has headers):

Code:
Sub FilterAndDelete()
 Dim LR As Long
 LR = Cells(Rows.Count, "B").End(xlUp).Row
    Range("A1:E" & LR).Select
    Selection.AutoFilter
    ActiveSheet.Range("A1:E" & LR).AutoFilter Field:=5, Criteria1:="0"
    ActiveSheet.Range("A1:E" & LR).AutoFilter Field:=2, Criteria1:="<>RK003"
    ActiveSheet.Range("$A$1:$E$" & LR).Offset(1, 0).SpecialCells _
    (xlCellTypeVisible).EntireRow.Delete
    ActiveSheet.ShowAllData
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,698
Members
448,979
Latest member
DET4492

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