Deleting Rows using a Macro

ultracyclist

Active Member
Joined
Oct 6, 2010
Messages
271
Office Version
  1. 365
Platform
  1. Windows
I’m using the following macro to delete all rows that match my Array. Due to the number of different sites (>30), I would like to revise the array to keep all rows that match 2-3 criteria, plus any rows that have a blank value in column F, but remove all others.</SPAN>


Code:
 </SPAN></SPAN>

Sub Row_Deletion_TEst()
    Dim ndx As Long
    Dim arrLike As Variant
    Dim Found As Range
    Dim ws As Worksheet
    
    arrLike = Array("CX-CD-LQ", "CX-CD-CB", "CX-CD-BB", "ZZ-ID-ID", "ZZ-ID-MA", "CX-NP-NC","CX-NP-NC","CST1","CST2")
    
    Application.ScreenUpdating = False
    
    For Each ws In Sheets(Array("Sheet1"))
          
        For ndx = LBound(arrLike) To UBound(arrLike)
        
            Do
                Set Found = ws.Columns("F").Find(arrLike(ndx), LookAt:=xlPart, MatchCase:=False)
                
                If Not Found Is Nothing Then Found.EntireRow.Delete
                
            Loop Until Found Is Nothing
            
        Next ndx
        
           
    Next ws
    
    Application.ScreenUpdating = True
    
    MsgBox "Row Delete Series Complete!"
End Sub


Thoughts?
</SPAN>
Thanks,</SPAN>
Allen </SPAN>
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
maybe...
Code:
     If Not found Is Nothing Then
        If found.Value <> "" Or _
          found.Value <> "criteria1" Or _
          found.Value <> "criteria2" Or _
          found.Value <> "criteria3" Then
            found.EntireRow.Delete
        End If
    End If
 
Upvote 0
I tried the following using the code provided, but it generates an error on the first line "If Not found Is Nothing Then"
Sub TestDelete()
If Not found Is Nothing Then
If found.Value <> "" Or _
found.Value <> "IL-CD-MB" Or _
found.Value <> "IL-CD-LB" Then
found.EntireRow.Delete
End If
End If
End Sub


The error message is a run time error 424 Object Required
 
Upvote 0
I didn't specify...

Use your existing code but replace
Code:
If Not Found Is Nothing Then Found.EntireRow.Delete
with the code I posted earlier.
 
Upvote 0

Forum statistics

Threads
1,203,076
Messages
6,053,395
Members
444,661
Latest member
liamoohay

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