VBA - Delete row if cell start with "this" or "that"

kparadise

Board Regular
Joined
Aug 13, 2015
Messages
186
Hello,

Looking for VBA code to put in my Module. I have Columns A:D which can have different amount of rows each time i run the code. What I am trying to do is to look in Column D, called "TYPE" and delete and row if the cell in Column D starts with either "Green-" or "Red-".
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Assuming that your data starts on row 1, try this:
Code:
Sub DeleteMacro()

    Dim lRows As Long

'   Filter to only show "Green-" and "Red-" entries in Type column
    Range("A1").CurrentRegion.AutoFilter Field:=4, Criteria1:="=Green-", _
        Operator:=xlOr, Criteria2:="=Red-"

    Application.ScreenUpdating = False
        
'   Delete hidden rows
    For lRows = ActiveSheet.UsedRange.Rows.Count To 1 Step -1
        If Cells(lRows, 1).EntireRow.Hidden = True Then Cells(lRows, 1).EntireRow.Delete
    Next lRows

    Application.ScreenUpdating = True
    
'   Remove filter
    ActiveSheet.UsedRange.AutoFilter
    
End Sub
 
Upvote 0
Excellent. Glad you were able to adapt it to work for you.
 
Upvote 0

Forum statistics

Threads
1,224,739
Messages
6,180,676
Members
452,993
Latest member
FDARYABEE

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