Addition to Delete Row Criteria

wayneshirley

Board Regular
Joined
Jun 23, 2003
Messages
140
Hi there,

I have a piece of vba that looks at data in column A. When it finds "7999" and "8999" it deletes the entire row.

Is it possible to add "A401" and "A451" to this?

Code
With Range("A1", Range("A" & Rows.Count).End(xlUp))
.AutoFilter Field:=1, Criteria1:="7999", Operator:=xlOr, _
Criteria2:="8999"
.Offset(1).EntireRow.Delete
.AutoFilter
End With

Thank you.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Hi there,

I have a piece of vba that looks at data in column A. When it finds "7999" and "8999" it deletes the entire row.

Is it possible to add "A401" and "A451" to this?

Code
With Range("A1", Range("A" & Rows.Count).End(xlUp))
.AutoFilter Field:=1, Criteria1:="7999", Operator:=xlOr, _
Criteria2:="8999"
.Offset(1).EntireRow.Delete
.AutoFilter
End With
Thank you.

Try this...
Code:
With Range("A1", Range("A" & Rows.Count).End(xlUp))
.AutoFilter Field:=1, Criteria1:="7999", Operator:=xlOr, _
Criteria2:="8999", Operator:=xlOr, _
Criteria3:="A401", Operator:=xlOr, _
Criteria4:="A451"
.Offset(1).EntireRow.Delete
.AutoFilter
End With
 
Upvote 0
I have tried this code but Criteria3:= is highlighted with the error message "Compile Error: Named argument not named."

Can you help please?
 
Upvote 0
Hi there,

Try this alternative method that deletes the rows for each element in the 'vMyArray' array (which can simply added to).

Note I've adapted this from Rick Rothstein's very clever Delete Row With Specific Word

Regards,

Robert

Code:
'http://www.mrexcel.com/forum/showthread.php?t=567491
Sub Macro1()

    Dim vMyArray As Variant
    Dim vArrayItem As Variant
        
    vMyArray = Array("7999", "8999", "A401", "A451")
    
    Application.ScreenUpdating = False
    
    For Each vArrayItem In vMyArray
                
        With Range("A1", Range("A" & Rows.Count).End(xlUp))
            .Replace vArrayItem, "#N/A", xlWhole 'Based on Rick Rothstein's very clever Delete Row With Specific Word from here: http://www.contextures.com/rickrothsteinexcelvbatext.html
            On Error Resume Next ' Account for no cells being found.
                .SpecialCells(xlCellTypeConstants, xlErrors).EntireRow.Delete
            On Error GoTo 0
        End With
        
    Next vArrayItem
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,750
Members
452,940
Latest member
rootytrip

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