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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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,609
Messages
6,179,874
Members
452,949
Latest member
Dupuhini

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